You want a lazy match.
A.*B given ABBBBBBBBBBBBBE can be though of as trying to match:
ABBBBBBBBBBBBBE
^-------------^
Going "that doesn't match" and trying one letter less
ABBBBBBBBBBBBBE
^------------^
Going "that does match" and returning it
A lazy match A.*?B
will try and match as little as possible. In this case:
ABBBBBBBBBBBBBE
^^
A and 0 characters then B, and will be like "That's a match" and return just AB
? usually means optional, but as * is a quantifier (0 or more) ? acts upon it to make it lazy.
You want F.*?G