Reputation: 409
So I have the following requirements:
So far, to solve this I have got the 2 following regex:
^[a-zA-Z][a-zA-Z ]*$
This is to solve points 1,2,3
(?<=[a-zA-Z])[.\-'](?=[a-zA-Z])
and this is to solve points 4,5
Test cases can be words like:
However I am unable to combine them. I have tried and I do not get the expected outcome. Any ideas?
Upvotes: 2
Views: 584
Reputation: 626816
You may use
^[a-zA-Z]+(?:[-.'][a-zA-Z]+)*$
See the regex demo
Details
^
- start of string[a-zA-Z]+
- 1+ ASCII letters(?:[-.'][a-zA-Z]+)*
- 0 or more occurrences of
[-.']
- a hyphen, dot or single quote[a-zA-Z]+
- 1+ ASCII letters$
- end of stringUpvotes: 1