Well, you can simply list the parameters individually:
^(A{2,3}|A{1,2}B|ABA|BA{1,2})$ β β β β β β β ββ starting with B β β ββββββ B in the middle β ββββββββββββββ B at the end βββββββββββββββββββββ only A
source share