tags:

views:

48

answers:

1

I was reading about regular expressions (I'm a regex newbie, but want to learn them) and came across this regex:

/^(?!http:\/\/www.google.com).*/

and I didn't know what or when it would match...so my question is just that, what/when would this regex match?

Thanks for helping out a regex padawan!

+7  A: 

That's a negative lookahead. It matches anything that doesn't start with:

http://www.google.com

(where the dots can be any character, which is probably not intended).

Mark Byers
In my feeling, a negative lookbehind would be more appropriate. This confuses me ;)
Felix Kling
@Felix: What's confusing about it? The first thing the regex does is look ahead to see if the subexpression matches at the beginning of the string. How could a lookbehind be more appropriate?
Alan Moore