Regex: How to optionally match something at beginning or end, but not both

regex

I have situation where in the regular expression is something like this:
^b?A+b?$

So b may match at the start of the string 0 or 1 times, and A must match one or more times. Again b may match at the end of the string 0 or 1 times.

Now I want to modify this regular expression in such way that it may match b either at the start or at the end of the string, but not both.

How do I do this?

Best Solution

Theres a nice "or" operator in regexps you can use.

^(b?A+|A+b?)$