in reply to Re^6: Replace zero-width grouping? (optimizing perl code)
in thread Replace zero-width grouping?

"Assertion" is the wrong word here because unless you do gymnastics the code block has no affect on whether the expression succeeds or fails. On the rare occasion that I want to use perl code in an assertion (and this never happens for "real" code) you have to use the eval block in a conditional and then use zero-width assertions to simulate a true-false.

/(? # Use the conditional construct (?{ perl code goes here}) # Perl code that will assert something (?=) # empty positive assertion. | (?!) # empty negative assertion )/x

Replies are listed 'Best First'.
Re^8: Replace zero-width grouping? ( (??{ }) ?)
by Aristotle (Chancellor) on May 09, 2003 at 18:58 UTC
    Why don't you use (??{ }) for that?

    Makeshifts last the longest.

      Huh. I wouldn't have thought to use (??{}) for that and still won't. It invokes the regex compiler which isn't necessary for the code2assert I posted. This works identically except its slower.

      /(??{ # delayed regex $condition ? '' # Nothing needed - this succeeds by default : '(?!)' # Failed! })/