[removed] replace last occurrence of text in a string

后端 未结 14 782
一整个雨季
一整个雨季 2020-12-02 18:13

See my code snippet below:

var list = [\'one\', \'two\', \'three\', \'four\'];
var str = \'one two, one three, one four, one\';
for ( var i = 0; i < list.         


        
14条回答
  •  时光取名叫无心
    2020-12-02 18:38

    Well, if the string really ends with the pattern, you could do this:

    str = str.replace(new RegExp(list[i] + '$'), 'finish');
    

提交回复
热议问题