Finding the last match before a first match

Answer

Assuming 'a' in the question may not really be just a single character...

/(.*)(a.*foo)/
Note:

Next