I am trying to use the regex function of JavaScript to replace my string with desired value.But the regex keeps failing when the string has this format '(content)'
Here's my code for Regex:
changeFormat = function (oldValue, newValue) {
var changeData = "http://www.semanticweb.ontology-91#rabindranath_tagore_(film)";
var regex = new RegExp(oldValue, 'g');
console.log(regex);
var source = changeData.replace(regex, newValue);
console.log(source);
};
changeFormat("http://www.semanticweb.ontology-91#rabindranath_tagore_(film)","rabindranath_tagore_(film)");
I got my output as "http://www.semanticweb.ontology-91#rabindranath_tagore_(film)" instead of "rabindranath_tagore_(film)"
The above behavior is because of the brackets "()".