See the following script by Peter Kahrel:
If the "A" and the "B" are in arbitrary positions in your text you could use the following GREP:
together with the script.
For testing your GREP expressions, you could use the following script, also by Peter Kahrel:
A GREP editor