Reputation: 2052
I was going through a piece of code and I hit against this syntax
str.replace(re,function(raw, p1, p2, p3){
if (!/\/\//.test(p1)) { // <---- this one
//some more code
}
});
I understand that the test method matches one string with another, and checks if it is present. But what does this regex /\/\//
matching the string to?
I checked the regex, and
\/ matches the character / literally
\/ matches the character / literally
so what does if(!//.test(p1))
doing?
Upvotes: 2
Views: 66
Reputation: 272
\/
matches the character /
literally. The above regex will execute if condition if there are no 2 consecutive /
.
check out this: here
Upvotes: 1
Reputation: 1
If first captured group ()
p1
contains //
return false
at if
condition by converting true
to false
using !
operator
Upvotes: 1
Reputation: 98469
The conditional is true if the string does not contain two consecutive slashes.
Upvotes: 5