Reputation: 35853
What does the ?!
mean in the following regex expression?
new RegExp('http:\/\/(?!' + location.hostname + ')')
Upvotes: 67
Views: 63751
Reputation: 354566
It's a negative lookahead, which means that for the expression to match, the part within (?!...)
must not match. In this case the regex matches http://
only when it is not followed by the current host name (roughly, see Thilo's comment).
Upvotes: 93
Reputation: 31733
It's a look around.
location.hostname
must not follow http:\/\/
Upvotes: 0