I am facing some issues in validating international email addresses like john.doe@神谕.com
, sara.smith@神谕.com
, babu.ratnakar+आଆఉఊګ神谕@gmail.com
,
testæœö.神谕#$&*éùôß@äßæçëêùé+आଆ神谕.com
using REGEX in C++
The following Regex worked fine for me in Java:
^[\\p{L}0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?$
I tried using the same with slight modification in C++
std::string str("[\\\\p{L}0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\\\\p{L}0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\\\p{L}0-9](?:[\\\\p{L}0-9-]*[\\\\p{L}0-9])?\.)+[\\\\p{L}0-9](?:[\\\\p{L}0-9-]*[\\\\p{L}0-9])?");
std::regex rx4(str);
But regex_match
fails on all cases. I think the issue is with \p{L}
. When I replaced that with a-z
, it accepts email addresses with english alphabets. ie this one is working:
std::regex rx3("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", std::regex::ECMAScript);
/p{L}
to match unicode letters won't work in C++ ?