Reputation: 332
I want to remove the last character from a string if it is a pipe. I have
.replace(/\|(\s+)?$/, '')
I want to add a parameter delim
to replace since the last character changes. I am trying:
.replace(/\+delim +(\s+)?$/, '')
but no luck.
The code that uses this function:
rangeValues[cellRow][hn[j]] = rangeValues[cellRow][hn[j]].toString()
.split(frValues[i][0])
.join(frValues[i][1]).trim()
.replace(/\ + delim + (\s+)?$/, '');
Upvotes: 1
Views: 87
Reputation: 201388
delim
in the regex.If my understanding for your question is correct, how about using RegExp?
var delim = "|";
var string = "\\" + delim + "(\\s+)?$";
var regex = new RegExp(string);
rangeValues[cellRow][hn[j]] = rangeValues[cellRow][hn[j]].toString()
.split(frValues[i][0])
.join(frValues[i][1]).trim()
.replace(regex, '');
delim
is |
, regex
becomes /\|(\s+)?$/
.If I misunderstand your question, I'm sorry.
Upvotes: 1