Accent in Regular Expression in Java

Rafael picture Rafael · Apr 20, 2011 · Viewed 16k times · Source

I'd like to use Hibernate Validator to validate some columns. The problem, as I understand, is that the \w marker in java doesn't accept letters with accents on them.

Is there any way that I could write the regexp so that words like Relatório could be validated (i wouldn't want to write all letters with accents between brackets, because I expect to be writing this regexp in a lot of columns)?

Answer

Rachel Shallit picture Rachel Shallit · Apr 20, 2011

The Java regex documentation has a section on Unicode categories (search for "Classes for Unicode blocks and categories"). If you're just looking for letters, I think \p{L} is the category you want.