I have regex /^\S.*$/ that matches almost any charset including Chinese, Arabic, Cyrillic, etc. characters (which is important for my use case). The problem with this regex is it also matches special characters. I don't need other special characters except ,, ., ', and -. How should I modify my regex?
Add a comment
|
1 Answer
You might be looking for \p{L} which "matches any kind of letter from any language" according to Regex101.com
4 Comments
Brian Kung
Also see this question: stackoverflow.com/questions/14891129/…
Bargain23
Pardon my ignorance but why does
/\p{L}/.test("مجيد الألم "); return false in Node?Brian Kung
No need to apologize! Looks like
\p expressions probably just aren't supported in the default JS environment. This library supports it: regular-expressions.info/xregexp.html MY apologies, I assumed it would work after testing it in regex101Brian Kung
Looks like someone extracted the
\p specific functionality here: npmjs.com/package/js-regex-pl And according to this answer, JS will support it starting in ECMAScript 2018