Category shorthand not allowed in this regular expression dialect in TypeScript

Viewed 648

I tried to use a regular expression in TypeScript:

const pass = /^[\pL\pM\pN_-]+$/u.test(control.value) || !control.value;

but I got this error:

Category shorthand not allowed in this regular expression dialect in Typescript

Why am I getting this error, and how can I fix it?

1 Answers

That regex shorthand (\pL) isn't allowed.

You'll need to use the full versions (\p{L}), instead of the shorthand:

const pass = /^[\p{L}\p{M}\p{N}_-]+$/u.test(control.value) || !control.value;
Related