I am trying use javascript regular expressions to do some matching and I found a really unusual behavior that I was hoping someone could explain.
The string I was trying to match was: ” 0 (IR) ” and the code block was
finalRegEx = new RegExp("[0-9]");
match = finalRegEx.exec(str);
except that when I put “\d” instead of “[0-9]” it didn’t find a match. I’m really confused by this.
If you use RegExp with
"\d"to build the regular expression, the"\d"will result in just"d". Either use two back slashes to escape the slash like"\\d"or simply use the regular expression literals/…/instead: