Skip to content
Advertisement

Java regular expression. Alphabetic, with spaces and apostrophe (‘)

what is the pattern to validate the following regular expression in java. string with only letters, spaces and apostrophes (‘)

I know that for letters is this ("^[a-zA-Z]+$") For spaces is this ("\s) I don’t know what apostrophe is.

But most of all i just want a single expression. Not 3 individual ones.

Advertisement

Answer

You can create your own class with the characters that you need to match, like this:

Pattern.compile("[a-zA-Z\s']+");
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement