Is /[\00]/v valid?

Proposal: GitHub - tc39/proposal-regexp-v-flag: UTS18 set notation in regular expressions

Just want to ask if /[\00]/v is valid. From the spec text, looks like it should be (and represents a character class of two characters), but V8 throws a "Invalid regular expression: /[\00]/v: Invalid class escape". Is this a V8 bug?

\0 isn't a valid regular expression for anything, even in the new v mode. Some regex engines ignore unnecessary escapes but not all engines do.

What character class were you expecting to match with this?

This isn't exactly right—\0 is the character escape for the NULL character and it's supported in all modes.

However, I now see why it's invalid—it's because \0 followed by another digit becomes the deprecated octal escape sequence, which is forbidden in u and v modes.

1 Like