in reply to Re^2: Regex libraries
in thread Regex libraries

/(?=.*\.)/ and /[^.]*/ are not the same thing at all.

'booga' =~ /[^.]*/ matches. 'booga.' =~ /[^.]*/ matches. 'booga' =~ /(?=.*\.)/ does not match. 'booga.' =~ /(?=.*\.)/ matches. '4.6.8' =~ /[^.]*\.(\d)/ returns 6 in $1. '4.6.8' =~ /(?=.*\.)(\d)/ returns 4 in $1. '4.6.8' =~ /((?=.*\.))\1(\d)/ returns 8 in $2. .* matched a "4.6" '4.6.8' =~ /.*\.(\d)/ returns 8 in $1. Lookahead not needed. '4.6.8' =~ /(?:(?!\.).)*(\d)/ returns 6 in $1. You want neg lookahead

/(?=.*\.)/ requires a "." in the string. /[^.]*/ does not requires a "." in the string. /[^.]*/ is equivalent of the negative lookahead /(?:(?!\.).)*/. The advantage of the negative lookahead version is that you can negatively match more than one character: /(?:(?!$re).)*/. If I only wanted to negatively match one character, I'd use [^...], even in Perl.

Side thought: Hum, It would be nice if /(?:(?!$re).)*/ could be shortcutted to /(?^$re)/, since that's the typical use of a negative lookahead.