Ricky
Ricky

Reputation: 35853

What does ?! mean?

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

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

Upvotes: 67

Views: 63751

Answers (3)

Joey
Joey

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

Jürgen Steinblock
Jürgen Steinblock

Reputation: 31733

It's a look around.

location.hostname must not follow http:\/\/

Upvotes: 0

npinti
npinti

Reputation: 52185

It's a negative lookahead, you can check here for more information.

Upvotes: 6

Related Questions