I need to check if a string starts with the following: “+=”
I’ve tried
str.search("+="));
and
str.search("\+\="));
but get
Uncaught SyntaxError: Invalid regular
expression: /+=/: Nothing to repeat
Can you help me with this, and also recommend a good resource for JavaScript regular expressions?
Try this regex:
It will return
trueif the string starts with+=. The^(caret) says “match from the beginning of the string”. The+needs to be escaped because it is a regex metacharacter that means “one or more of the preceding” (and that’s not what we want).