If you change the middle quantifier from non-greedy to greedy, it will try to match the longest possible part.
In reply to Re^3: Working with files by Corion in thread Working with files by AmberThai