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

I am trying to formulate a regular expression that identifies lines that begin and end with "B" but also have an odd number of letters in total. So far I have the following:

Lines starting and ending with B:

^B.*B$ 

I'm not sure how to get it so that it accepts an odd number of letters. For even numbers, this is easy:

 ^B(..)*B$ 

But the odd one throws me a little

+4
source share
1 answer

It should be almost the same:

 ^B.(..)*B$ 
+7
source

All Articles