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.
Well, if the string really ends with the pattern, you could do this:
str = str.replace(new RegExp(list[i] + '$'), 'finish');