Human: How to replace only part of the match with python re.sub Assistant: 
Here is some code to insert `_suff` before the file extension in `long.file.name.jpg` or replace `_a` with `suff` if it precedes the extension.

re.sub('(\\_a)?\\.([^\\.]*)$', '_suff.\\2', 'long.file.name.jpg')

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.