in reply to left-non-greedy regex?

Some test strings...

$a[0] = "abbabbbababba"; $a[1] = "ababbabbba"; $a[2] = "abbbabbaba";

The goal is to match the single b with the same regex in each case.

andramoiennepemousapolutropon

Replies are listed 'Best First'.
Re: Re: left-non-greedy regex?
by Paladin (Vicar) on Mar 25, 2003 at 18:18 UTC
    This is fairly easy using negative look-ahead and negative look-behind:
    use English; @a = qw/abbabbbababba ababbabbba abbbabbaba/; foreach (@a) { print "$PREMATCH $MATCH $POSTMATCH\n" if /(?<!b)b(?!b)/ } abbabbba b abba a b abbabbba abbbabba b a

    i.e: Only match a b if there is no b before or after it. Although this doesn't really have to do with what you were talking about in the root node, it is one of the easiest ways of doing it.