The "/" character is an escape character. For example if you want to alert "the "big" cat" with the word cat in quotes one way of doing it is alert("the \"big\" cat");
Because you are providing a string you need to escape the escape
Try the following 2 examples
alert("\(") // => ( alert("\\(") // => \(
What you want is the second example as the "correct" grep is \( and not (
Another way to explain the double-escape trick is to consider those two distinct levels:
1. At the GREP (or regular expression) level, parentheses ( and ) are special symbols that control capturing groups.
So if you want to capture a left parenthesis as itself you need to use an escape sequence.
In GREP, the escape character is \ (backslash) so that the full escape sequence is \( (backslash + parenthesis.)
So if you want to provide the backslash as itself in a literal string, you need the following escape sequence, "\\" (backslash + backslash), which in fact represents a single backslash character.
[The reasoning is the same for square brackets.]
Hope that helps.
Thank you Trevor.
I'm used to the UI GREP codes, so I appreciate your short and sweet explanation that JS strings are different