-1

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?

Bargain23
  • 1,863
  • 3
  • 29
  • 50

1 Answers1

1

You might be looking for \p{L} which "matches any kind of letter from any language" according to Regex101.com

Brian Kung
  • 3,957
  • 4
  • 21
  • 30
  • Also see this question: https://stackoverflow.com/questions/14891129/regular-expression-pl-and-pn – Brian Kung Mar 19 '18 at 18:06
  • Pardon my ignorance but why does `/\p{L}/.test("مجيد الألم ");` return false in Node? – Bargain23 Mar 19 '18 at 18:09
  • No need to apologize! Looks like `\p` expressions probably just aren't supported in the default JS environment. This library supports it: http://www.regular-expressions.info/xregexp.html MY apologies, I assumed it would work after testing it in regex101 – Brian Kung Mar 19 '18 at 18:11
  • Looks like someone extracted the `\p` specific functionality here: https://www.npmjs.com/package/js-regex-pl And according to [this answer](https://stackoverflow.com/a/13210296/1042144), JS will support it starting in ECMAScript 2018 – Brian Kung Mar 19 '18 at 18:13