diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
use Term::ANSIColor ':constants'; # Note that there is not normally a space betweeh the </ and code>. I +added that so that Perlmonks.org wouldn't parse the post incorrectly. $_ = "normal <code> green <!-- yellow [red] normal --> normal </ code> + normal"; $GREEN = GREEN; $YELLOW = YELLOW; $RED = RED; $RESET = RESET; s(<code>(.+?)</ code>)($GREEN$1$RESET)g; s((?<=\x1b)\[(.+?)\])($RED$1$RESET)g; s((<!--.+?-->))($YELLOW$1$RESET)g;
The preceding program produces the following string. Overlapping is not detected and each markup element terminates the enclosing element prematurely.
"normal " . GREEN . " green " . YELLOW . "<!-- yellow " . RED . "red" . RESET . " normal -->" . RESET . " normal" . RESET . " normal"I'd like it to produce this. If perl had variable length look-behind I'd write this as (?<=(?:^|$RESET)[^\x1b]*). Any ideas for how to write this without using perl's experimental regexp features ( (?{ code }), (??{ rx }), and (?(expr)true|false))?
"normal " . GREEN . " green <!-- yellow [red] normal --> normal" . RESET . " normal"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Substitute for variable-length look-behind?
by particle (Vicar) on Jan 26, 2004 at 18:15 UTC | |
by belg4mit (Prior) on Jan 26, 2004 at 21:56 UTC | |
Re: Substitute for variable-length look-behind?
by Roy Johnson (Monsignor) on Jan 26, 2004 at 19:35 UTC | |
Re: Substitute for variable-length look-behind?
by diotalevi (Canon) on Jan 26, 2004 at 21:13 UTC | |
Re: Substitute for variable-length look-behind?
by bart (Canon) on Jan 26, 2004 at 20:30 UTC | |
Re: Substitute for variable-length look-behind?
by Roy Johnson (Monsignor) on Jan 26, 2004 at 18:25 UTC | |
Re: Substitute for variable-length look-behind?
by sleepingsquirrel (Chaplain) on Jan 26, 2004 at 19:18 UTC | |
Re: Substitute for variable-length look-behind?
by Abigail-II (Bishop) on Jan 26, 2004 at 17:48 UTC |