how to replace last occurrence of a word in javascript?

前端 未结 3 772
不知归路
不知归路 2020-12-20 15:35

for example:

var str=\"
hi
hi\";

to replace the last(second)
,

to change into \"<

3条回答
  •  一个人的身影
    2020-12-20 16:19

    I think you want this:

    str.replace(/^(.*)
    (.*?)$/, '$1$2')

    This greedily matches everything from the start to a
    , then a
    , then ungreedily matches everything to the end.

提交回复
热议问题