Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine regex character classes

Regex pattern /[^[:ascii:]]+/ui will match one or more non-ascii characters.

Regex pattern /[\p{L}]+/ui will match one or more characters in unicode ‘letter’ class.

I can’t figure out a way how to match one or more characters that are in unicode ‘letter’ class AND are not ascii characters.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use a negated character class like this:

[^\P{L}[:ascii:]]+

RegEx Demo 1

This will match 1+ of any character that is not an ASCII and not matched by \P{L} (inverse of \p{L})


Alternatively, you can use negative lookahead in a non-capture group:

(?:(?![[:ascii:]])\p{L})+

RegEx Demo 2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading