Issue
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?
Solution
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;
Answered By – Cerbrus
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0