Sandah Aung Sandah Aung - 4 months ago 10
Java Question

Regex for character range and space

I use the following to check if a given string

unicodeName
is within a certain character range:

unicodeName.matches(".*[^\u1000-\u103f].*")


However, this does not allow for the inclusion of space characters in the name. If I want the user to type space in the name and at the same time want the matcher to return true what would the regex be?

Example:

This works fine for me

works

but this doesn't

enter image description here

Answer

I would use:

^[\\s\\u1000-\\u103f]*$

(don't forget to escape \)