in reply to Perl's regexp (?{...}) construct and constraining matches.

Use (?=) for success and (?!) for failure. That is easier to understand and more direct than \w\b\w. You end up with (?(?{ PERL-CODE }) (?=) | (?!) ). You can write only the failure condition by negating the result of the perl code: (? (?{ not PERL-CODE }) (?!) )

Replies are listed 'Best First'.
Re^2: Perl's regexp (?{...}) construct and constraining matches.
by davido (Cardinal) on Aug 14, 2004 at 15:51 UTC

    Thanks diotalevi, I was struggling to come up with guaranteed failure condition. \w\b\w works, but your solution is more elegant.

    Implementing your suggestions, the regexp now looks like:

    m/$find(?(?{not(pos()<=length($_)*.5)})(?!))/

    Starting to look a little saner.


    Dave

      Of course, as with everything else, sanity is relative… :-)

      Makeshifts last the longest.

      You know, would it kill you to call your mother? She's been waiting to tell you your regexes need more whitespace.