Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^8: This regexp made simpler

by rubasov (Friar)
on Apr 26, 2010 at 14:31 UTC ( #836922=note: print w/replies, xml ) Need Help??


in reply to Re^7: This regexp made simpler
in thread This regexp made simpler

To satisfy my curiosity I wrote the backtracking control version you mentioned and I was surprised how simple it is:
while (<DATA>) { print; s[ ^ (START) ( | \s.*? ) (END) (*COMMIT) $ ] [ $1 . $2 . 'insert' . $3 ]ex; print; } __DATA__ STARTEND STARTENDEND START SOMETHING END STARTSOMETHINGEND START END START ENDEND STARTSTARTENDEND STARTSTART ENDEND

For comparison here's the other form:

s[ ^ (START) ( | \s (?:(?!END).)* ) (END) $ ] [ $1 . $2 . 'insert' . $3 ]ex;