Finding the last match before a first match


I need to find the first match before another match.

With the string 'abcdefgabcdefgfooabcdefg', I need to match 'foo' and the 'a' previous to but nearest 'foo' (not the one at the beginning of the string).

There's an unknown number of characters between the 'a' and the 'foo'.

Greg Carlson's original post