kentor
kentor

Reputation: 18552

How to use any letter from any langugage in regex

Use case:

I have the following string '파이어 볼' and I want to check if each symbol in the string is a valid letter in any language.

What I've tried:

To do this, I found the following regex pattern that is supposed to match "any letter in any language".

/\p{L}/

The pattern successfully matched on the major regex helper websites (regex101, regexcoach, regexer) I tested. They all returned the 4 symbols as matches, as intended.

Now when I try this in my javascript/node.js application it doesn't work, see the following snippet:

if (/\p{L}/.test('파이어 볼')) {
  alert('true'); 
}
else {
  alert('false');
}

Question:

How can I properly test if a given character is a valid letter in any language.

Upvotes: 0

Views: 98

Answers (1)

Riki
Riki

Reputation: 1806

Javascript doesn't properly unicode regex. Use this library as it fixes the missing functionality:

https://www.npmjs.com/package/js-regex-pl

Upvotes: 1

Related Questions