'python regex for a letter must be surrounded by a another letter

I'm trying to write a regex that only matches a string that includes lowercase a & b such that each a has the letter b immediately before it and after it.

e.g., the Regex should match the string 'bbbabbababbbbab' but not 'abbbbaabbab'

I have written an expression that does satisfy the example however, the regex should also match a string such as 'bab' but it does not.

My current expression is ^[b]+(ab)+[ab]*[b]$

Anyone have any advice on what I'm doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source