Search code examples
javascriptregexstring-matching

what does the following java script expression mean


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?


Solution

  • The conditional is true if the string does not contain two consecutive slashes.