in reply to Re: "Not containing something" in substitution
in thread "Not containing something" in substitution

Neat RegEx. Note that this does not solve strat's problem with this RegEx, as he is looking for a substitution and not a matching, and as it is nested it will be really hard to do a substitution with it. This can be understood as a challenge ;-).
Still, I modified the RegEx a bit to work with strat's problem, at least for matching
use re 'eval'; $begin = '[xyz]'; $end = '[/xyz]'; $string = '[xyz]level 1.1 [xyz]level 2.1[/xyz] rest of 1.1 [/xyz]'; $re = qr{ \Q$begin\E (?: (?> (?:(?!=\Q$begin\E|\Q$end\E).)+ ) | (??{ $re }) )* \Q$end\E }x; print 'Yeah!' if $string =~ $re;
I just have too much free time ;-)
Cheers, CombatSquirrel.
Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re^3: "Not containing something" in substitution
by Aristotle (Chancellor) on Aug 28, 2003 at 12:57 UTC
    Why?
    use strict; use warnings; use re 'eval'; my $begin = qr!\Q[xyz]!; my $end = qr!\Q[/xyz]!; my @match; my $re; $re = qr{ $begin ( (?: (?> (?:(?!=$begin|$end).)+ ) | (??{ $re }) )* ) $end }x; $_ = '[xyz][xyz]level 1.1 [xyz]level 2.1[/xyz] rest of 1.1 [/xyz]'; 1 while s!$re!<xyz>$1</xyz>!; print; __END__ <xyz><xyz>level 1.1 [xyz]level 2.1</xyz> rest of 1.1 </xyz>

    Makeshifts last the longest.