I need to match a pattern that starts with a capital letter, is followed by a series of the same letter in lowercase, and then ends with the same letter capitalized again.
Should Match:
XxxxX
NnN
YyyyyyyY
Should Not Match:
XyyyX
XxxxB
XyyyZ
I know how to match the two capital letters using backreferences, but I’m not sure how to capture the middle portion where the letter needs to be the same but a different case.
Thanks.
You can’t do it all in a single regular expression. You can test most of it using a regular expression, but you need a separate test to see if the upper and lower case letters are the same:
Note: Here I’m assuming that you only want A-Z.