I want to replace this: "[ID]" with this "ad231-3213-e12211"
I used this regex: /\[ID\]/i
And he worked great with .replace(/\[ID\]/i, id)
Now I encapsulated it in this function:
self.changeUrl = function (url, id, replaceExp) {
replaceExp = replaceExp === 'undefined' ? new RegExp("\[ID\]") : replaceExp instanceof RegExp ? replaceExp : new RegExp("\[ID\]");
return url.replace(replaceExp, id);
};
and this:
self.changeUrl = function (url, id, replaceExp) {
replaceExp = replaceExp === 'undefined' ? new RegExp("\u005BID\u005D") : replaceExp instanceof RegExp ? replaceExp : new RegExp("\u005BID\u005D");
return url.replace(replaceExp, id);
};
And none of them work, what am I missing?
source
share