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

[REBOL] Re: questions about VID and parse.

From: joel:neely:fedex at: 11-Mar-2002 7:53

Hi, Christophe, Coussement Christophe wrote:
> > Also another question about parse. How to use a string as a pattern? > > parse "hello world" ?? > > I want ["hello" "rld"] > > By what should I replace ?? to make this sequence ("wo" in this example) > > considered as a whole. > [Coussement Christophe] try: > >> parse "hello world" none > == ["hello" "world"] > >> >
I interpreted the question as wanting "wo" to be the marker/delimiter between fragments of the string, instead of whitespace. That could be done something like this: marker: "wo" fragment: "" collection: [] parse-rule: [ any [ copy fragment to marker (append collection fragment) marker ] copy fragment to end (append collection fragment) ] which gives:
>> parse "hello world" parse-rule
== true
>> collection
== ["hello " "rld"] only leaving open the issue of the trailing whitespace in "hello ", but that wasn't stated in the delimiter... -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" ;