RegEx that will match the last occurrence of dot in a string

前端 未结 9 1183
梦如初夏
梦如初夏 2020-12-13 16:55

I have a filename that can have multiple dots in it and could end with any extension:

tro.lo.lo.lo.lo.lo.png

I need to use a regex to repla

9条回答
  •  自闭症患者
    2020-12-13 17:38

    Why not simply split the string and add said suffix to the second to last entry:

    var arr = 'tro.lo.lo.lo.lo.lo.zip'.split('.');
    arr[arr.length-2] += '@2x';
    var newString = arr.join('.');
    

提交回复
热议问题