I need find a line matching a pattern like: A xx B xx, where xx is a pattern that is either before or after B.
You may try:
A (xx B|B xx)