[REBOL] Re: Another question
From: al:bri:xtra at: 15-Feb-2002 17:34
Alex wrote:
> the original goal was to replace [red] with an escape character followed
by "[31m" for example), but I was hoping to go through the various color
tags ([red], [green], [blue] etc.) and search through the remainder of the
text after finding a tag regexp-style for the next tag. That way, no time
would be wasted re-scanning through the entire string to find new codes
That's possible with parse. It just a little trickier to write.
[rebol []
Text: "Sample Text with [red]RED, [green]GREEN and [blue]BLUE."
parse/all Text [
any [
[
Mark: "[red]" After: (
After: change/part Mark "ESC[31m" After
) :After
]
| [
Mark: "[green]" After: (
After: change/part Mark "ESC[31Gm" After
) :After
]
| [
Mark: "[blue]" After: (
After: change/part Mark "ESC[31Bm" After
) :After
]
| skip
]
]
probe Text
halt
]
And the result:
{Sample Text with ESC[31mRED, ESC[31GmGREEN and ESC[31BmBLUE.}
I hope that helps!
Andrew Martin
ICQ: 26227169 http://valley.150m.com/