One of our legacy JavaScript code contains this line of code:
code.match(/if\\s*\\(/g).length What does this /if\\s*\\(/g regex mean?
It means match "if" followed by whitespace "zero or more" times and an open parentheses. Except it should error because of the double escapes, the regular expression would be:
code.match(/if\s*\(/g).length A regular expression literal does not use double escapes, they're used in RegExp Objects.
var re = new RegExp('if\\s*\\(', 'g') code.match(re).length; In other words:

The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
Search a string for "ain":
var str = "The rain in SPAIN stays mainly in the plain"; var res = str.match(/ain/g); The result of res will be an array with the values:
ain,ain,ain