Home > Enterprise >  Combine regex character classes
Combine regex character classes

Time:06-05

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.

CodePudding user response:

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

  • Related