0

I have the following regex to match words that start with uppercase letters in text:

var mathes = text.match(/[a-z]*[A-Z]+[a-z]*/g);

This works fine except when matching international letters they are being ignored. This thread What does this regexp mean - "\p{Lu}"? suggests using the form \p{Lu} and \p{Ll} so I would assume it to work like this:

var mathes = text.match(/\p{Ll}*\p{Lu}+p{Ll}*/g);

However the matching of uppercase letters stops working.

How can I include matching international letters in words starting with uppercase?

doorman
  • 15,707
  • 22
  • 80
  • 145
  • Use `u` flag, `var mathes = text.match(/\p{Ll}*\p{Lu}+p{Ll}*/gu);` – Wiktor Stribiżew May 09 '21 at 11:41
  • Hi @WiktorStribiżew thanks for the suggestion. However I am getting the error Unknown property: Ll ... I also tried using the same pattern with XRegExp and I still get the same error. Any other suggestions? – doorman May 09 '21 at 14:02
  • You have a typo in the `\p{Ll}` that I copy/pasted into the top comment. Use `.match(/\p{Ll}*\p{Lu}+\p{Ll}*/gu)`, it works. – Wiktor Stribiżew May 09 '21 at 14:04
  • @WiktorStribiżew I am getting the same error in the sandbox https://codesandbox.io/s/match-regex-js-forked-rp0ej?file=/src/index.js Can you see there if I am missing something? – doorman May 09 '21 at 15:11
  • The environment is not ECMAScript 2018 compliant. See [a working JSFiddle](https://jsfiddle.net/wiktor_stribizew/0d8u1whz/). This won't work in Safari though. – Wiktor Stribiżew May 09 '21 at 17:42

0 Answers0