in reply to Re: Integrating match counts into regex matching
in thread Integrating match counts into regex matching

You used "(?<!a)" and "(?!b)" as anchors, so your solution was designed to match a substring, but it doesn't work for 'a_abb' (false negative) and 'a_abbb' (false positive).

for (qw[ ab abb abbb aabb aabbb aabbbb a_abb a_abbb ]) { m[ (?<!a) (?> (a+) (?{ length($^N) }) (b+) ) (?(?{ length($^N)-$^R != 1 })(?!)) ]x and print("$_\n"); }
abb aabbb a_abb

Replies are listed 'Best First'.
Re^3: Integrating match counts into regex matching
by BrowserUk (Patriarch) on Dec 19, 2008 at 09:29 UTC

    Indeed++ Hence the "Hmmm?"

    It can be dealt with:

    for( qw[ ab abb abbb aabb aabbb aabbbb a_abb a_abbb abbaabbbaaabbbaxab +b ] ) { print "$_ contains '$1'" while m[ ( (?<!a) (?{ local $a }) ( a (?{++$a}) )+ ( ?{ local $b }) ( b (?{++$b}) )+ (?!b ) ) (?(?{ $a+1 == $b }) (?=) | (?!) ) ]gx };; abb contains 'abb' aabbb contains 'aabbb' a_abb contains 'abb' abbaabbbaaabbbaxabb contains 'abb' abbaabbbaaabbbaxabb contains 'aabbb' abbaabbbaaabbbaxabb contains 'abb'

    But yours is a simpler approach, and probably quicker.

    But the primary purpose of posting was to demonstrate the regex if...then...else construct--not to do someone else's systems testing for them.

    Particularly as this is very unlikely to be the actual pattern they are trying to match


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.