Insert a string before the extension in a filename

后端 未结 7 1555
日久生厌
日久生厌 2021-02-05 03:58

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
7条回答
  •  甜味超标
    2021-02-05 04:01

    var s = '../Course/Assess/Responsive_Course_1_1.png'
    s.replace(/\.png$/, '_large.png');
    

    This will do the job. By the way, it's night here. :)

    UPDATE:

    A more general way would be this:

    var s = '../Course/Assess/Responsive_Course_1_1.png';
    s.replace(/(\.[^\.]+)$/, '_large$1');
    

提交回复
热议问题