Regular expression with latin characters

I have this regex:

if (cadena.matches("^[a-zA-Z ]+$")) return true; 

It takes A to Z both lowercase and uppercase. Also accepts spaces.

But this only works for English. For example, in Catalan we have the symbol "รง". We also have characters with 'รก', or 'ร ', etc.

Was there some kind of Google and I could not find a way to do this.

I found out that I can filter for UTF-8, but this will accept characters that are not actually letters.

How to implement this?

+11
source share
2 answers

Use this regex:

 [\p{L}\s]+ 

\p{L} means any Unicode letter.

fiddle.re Demo .

+20
source

Take a look at the documentation and use a class (for example, \p{InLatin1Supplemental} ).

-2
source

All Articles