Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Shutting off parse features

From: joel:neely:fedex at: 9-Mar-2002 10:11

Hi, Carl, Terry, and all A slightly more generic version... Carl Read wrote:
> On 09-Mar-02, Terry Brownell wrote: > > > When parsing a string such as {Hello world, "this to" is an > > example;} parse will remove the comma, and the semi... and takes > > anything within quotes as a single value. > > > Sometimes I just want to parse spaces so we get... > > ["Hello" "world," "this" "to" "is" "an" "example;"] >
...
> Well, the 'all refinement let's you parse everything except what you > tell it not to parse. ie... >
...
> Though your "this to" becomes one string instead of two. Close to > what you want though, and stripping out the speach-marks first would > be one option. ie... >
just-the-good-parts: func [ s [string!] /local result good-ones others fragment ][ good-ones: charset [#"A" - #"Z" #"a" - #"z" #"." #"," #";"] others: complement good-ones result: copy [] parse/all s [ any [ copy fragment some good-ones (append result fragment) | some others ] ] result ]
>> a: {Hello world, "this to" is an example;}
== {Hello world, "this to" is an example;}
>> just-the-good-parts a
== ["Hello" "world," "this" "to" "is" "an" "example;"] Suitable redefinitions of GOOD-ONES and OTHERS will let you keep or discard whatever characters you wish, of course. -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;