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
  • 233
  • 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).

As a workaround, use Boost library in C++.

In Boost, declare the regex as follows:

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

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

In ECMAScript used in JavaScript in modern browsers, you can use

var str = "bębnić";
var regex = /^\p{L}+$/u;
console.log(regex.test(str));

An XRegExp based solution in JavaScript for older browsers (like Safari):

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
  • 607,720
  • 39
  • 448
  • 563