Reputation: 29
I am new at programming Java and using Regular Expressions.
I am trying to learn more about regular expressions, and I have the following question.
I want to create a regex that will:
I have tried the following two regexes:
[a-zA-Z\\s{2,]]*|[a-zA-Z{2,}]
and
[a-zA-Z\\s]*|[a-zA-Z].{2,}
But they do not work. Can anyone help me understand how to write this regex?
Upvotes: 1
Views: 60
Reputation: 14699
Consolidated Restrictions:
Match strings consisting of at least 1 length 2+ character sequence restricted to the english characters (not sure if this is exactly what you want, but hopefully it will suffice):
regex = "^(?:\s*[a-zA-Z]{2,}\s*)+$"
"^": must begin with
"(?:...)": group, but do not capture
"\s": whitespace
"*": 0 or more
"[...]": character class
"[a-zA-Z]": restricts characters to lower/uppercase a,b,...,y,z
"{2,": 2 or more of the proceeding
"+": 1 or more
"$": must end here
Upvotes: 1