Insert a string before the extension in a filename

javascript, split, string

Solution

If we assume that an extension is any series of letters, numbers, underscore or dash after the last dot in the file name, then:

filename = filename.replace(/(\.[\w\d_-]+)$/i, '_large$1');

Problem

How can I insert a string before the extension in an image filename? For example, I need to convert this: ``` ../Course/Assess/Responsive_Course_1_1.png ``` to this: ``` ../Course/Assess/Responsive_Course_1_1_large.png ```

Original source