user559142
user559142

Reputation: 12517

How to match strings that start and end with the same character, but have an odd number of letters?

I'm trying to formulate a regex that identifies strings that begin and end with 'B" but also have an odd number of letters overall. So far I have the following:

Strings that start and end with B:

^B.*B$

I am not sure how to get it so that it only accepts an odd number of letter. For even numbers it's easy:

^B(..)*B$ 

But odd is throwing me a little

Upvotes: 4

Views: 439

Answers (1)

MByD
MByD

Reputation: 137312

It should be almost the same:

^B.(..)*B$

Upvotes: 7

Related Questions