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:
- This matches both everything before the desired target
and the desired target.
- This finds the last 'a' before the
last 'foo'.
Next