Home > Blockchain >  Category shorthand not allowed in this regular expression dialect in TypeScript
Category shorthand not allowed in this regular expression dialect in TypeScript

Time:10-28

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?

CodePudding user response:

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