in reply to Regular Expression matching question
First, I changed your grouping so I could see what was really happening:
So Perl finds a match quite easily and gives up; fair enough. Regexen are supposed to be greedy but that doesn't include trying a second alternative (something after a veritcal bar) to see if it can match a longer string that way. So lets force Perl to be less lazy by forcing a match to the end of the string:% perl -de 0 DB<1> x "ab" =~ /(a*)((?:ab)*|b*)/ 0 'a' 1 ''
Does that answer the question well enough for you? - tye (but my friends call me "Tye")DB<2> x "ab" =~ /(a*)((?:ab)*|b*)$/ 0 'a' 1 'b'
|
|---|