'What does ?! mean?
What does the ?! mean in the following regex expression?
new RegExp('http:\/\/(?!' + location.hostname + ')')
Solution 1:[1]
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).
Solution 2:[2]
It's a negative lookahead, you can check here for more information.
Solution 3:[3]
It's a look around.
location.hostname must not follow http:\/\/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kumarharsh |
| Solution 2 | npinti |
| Solution 3 | Jürgen Steinblock |
