in reply to Re: Regex libraries
in thread Regex libraries

You´re right.
If I dont have an important feature which I would miss in the future its quite useless to whine about something I dont have and actually dont know how to apply correctly.
Perhaps I expressed myself unclear (sorry for that) I do have one or two cases where Lookaheads are usefull but I am still thinking I could also write them in Boost. Unfortunatly I havent found out how yet:

Perl goes: /(?=.*\.)/

Boost goes: /[^.]*/

Actually I just got aware that the second regex without Lookahead is much more usefull because its more flexible. I simply didnt thought well enough about my problem.

I should take myself more time to think about problems. One week still isnt enough ;-) I probably should wipe my ideas if I havent solved them in one day.
The obvious often hides behind the complicated.

Anyhow. I just made the decision to use the library which is currently implemented. I was more frightend to have something I wouldnt be able to work with. And I needed to see this written down somewhere *g

Thanks for pointing me in the right direction

Replies are listed 'Best First'.
Re^3: Regex libraries
by ikegami (Patriarch) on Dec 31, 2004 at 18:58 UTC

    /(?=.*\.)/ 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.