2

I need to match all unicode characters in Email Addresses. I could do this validation in Java using \p{L}. Is there any \p{L} equivalent in JS and C++ ?

If not which is the best reliable open source library which provides this capability in C++ and JavaScript ?

vijin
  • 223
  • 4
  • 14

1 Answers1

3

ECMAScript, as well as all other flavors supported by the std::regex, does not support Unicode properties (Unicode category classes). JavaScript has this support neither.

As a workaround, use Boost library in C++ and XRegExp library in JavaScript.

In Boost, declare the regex as follows:

boost::wregex reg(L"^\\p{L}+$");

Note that ^\p{L}+$ matches 1+ letter strings only.

A JS example:

var str = "bębnić";
regex = XRegExp('^\\p{L}+$');
console.log(regex.test(str));
<script src="https://cdnjs.cloudflare.com/ajax/libs/xregexp/2.0.0/xregexp-all-min.js"></script>
Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476