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
In reply to Re: A complex recursive regex,help
by tachyon
in thread A complex recursive regex,help
by OM_Zen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |