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

前端 未结 9 1226
梦如初夏
梦如初夏 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:45

    Just use special replacement pattern $1 in the replacement string:

    console.log("tro.lo.lo.lo.lo.lo.png".replace(/\.([^.]+)$/, "@2x.$1"));
    // "tro.lo.lo.lo.lo.lo@2x.png"

提交回复
热议问题