RegExp /\c/ doesn't trigger any syntax error.
console.log(/\c/)
The question is why it's not a syntax error. Since the language spec, I'm guessing Pattern → Disjunction → Alternative → Term → Atom → \ AtomEscape → CharacterEscape → IdentityEscape, then it arrives at SourceCharacter but not c and it doesn't match by the condition but not c.
https://www.ecma-international.org/ecma-262/8.0/#sec-regular-expressions-patterns
I wonder if I'm wrong.
I found it.
The \c doesn't match to \ AtomEscape alternative. This was correct. So the \ letter matches to ExtendedPatternCharacter and the c letter matches to ExtendedPatternCharacter individually.
/^\x$/.test("x") //→ true
/^\c$/.test("c") //→ false
/^\c$/.test("\\c") //→ true
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