For example:
"1+1=2".replace(/=/,"aa");
"1+1=2".replace(/\=/,"aa");
return the same result.
Does it mean I don't have to escape "=" (the equal sign) in JavaScript? I remembered that I always have to escape equal sign in Java and .NET.
I tried to find some info from https://www.ecma-international.org/ecma-262/7.0/index.html but didn't come up with anything.
Can anyone help me find if the specification talks about escaping the equal sign?
I'd go with this table in MDN web docs. You'll see that =
has no special meaning - just as @Barmar stated. You referred to lookaheads, which use ?=
, but without the leading ?
it's just an equal sign.
There are not many special characters which needs an additional special character to "work", I guess that's why it's confusing. Think of it as -
in combination with [
and ]
:
0-9
matches "0-9"[0-9]
matches "0" and "1" and ... and "9"[0\-9]
matches "0" and "1" and ... and "9" and "-"
So just -
has no meaning and does not have to be escaped, only if combined with square brackets. The same applies to =
with/without ?
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With