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']+");