in reply to A complex recursive regex,help
You don't need recursion. Just use the positive look back and look forward assertions which don't eat string. See perlman:perlre
my $a = "x|xx|xx|xxxx|xx|xxx|xx|xx|x"; $a =~ s/(?<=\|)xx(?=\|)/x x/g; print "[$a]\n"; __DATA__ [x|x x|x x|xxxx|x x|xxx|x x|x x|x]
You don't say what you want to do with the edge cases:
$a = 'xx|xx|xx'; # should this be (use example above): [xx|x x|xx] # or should it be [x x|x x|x x] # in which case you will need to add an extra regex because you can't +have # variable width lookbacks. this regex just processes those edge cases $a =~ s/^xx(?=\|)|(?<=\|)xx$/x x/g; # combined with the first part gives you some real perl line noise # if you want it all in a single regex $a =~ s/^xx(?=\|)|(?<=\|)xx(?=\|)|(?<=\|)xx$/x x/g;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: A complex recursive regex,help
by OM_Zen (Scribe) on Feb 06, 2003 at 18:53 UTC | |
by tachyon (Chancellor) on Feb 06, 2003 at 23:14 UTC | |
|
Re: Re: A complex recursive regex,help
by OM_Zen (Scribe) on Feb 06, 2003 at 01:00 UTC | |
by tachyon (Chancellor) on Feb 06, 2003 at 01:07 UTC | |
by OM_Zen (Scribe) on Feb 06, 2003 at 01:12 UTC |