Regex – What Does ?! Mean?

regex

What does the ?! mean in the following regex expression?

new RegExp('http:\/\/(?!' + location.hostname + ')')

Best Answer

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).