I'm trying to replace portions of a textarea
text by regex.
propertiesText
is the full text received from the textarea
, and the replacement code is as follows:
var propertyName = inputs[i].name;
var propertyValue = inputs[i].value;
//#regexExpression = #propertyName=.* [example: /#EPCDatabase\/EPCdatabase.param\/epc.db.user=.*$/gim]//
var regexExpression = new RegExp(propertyName + "=.*$","gim");
//#newString = propertyName=propertyValue [example: EPCDatabase\/EPCdatabase.param\/epc.db.user=ddddd]//
var newString = propertyName.substring(1) + "=" + propertyValue;
console.log("Regex Expression: " + regexExpression);
console.log("Replace String: " + newString);
propertiesText.replace(regexExpression, newString);
console.log(propertiesText);
return;
In the console, I'm getting the following regex expression:
But the text is not being replaced in the original propertiesText
:
I've tried checking my regex and you can see it is matching.
I've also tried isolating the replacement code part with the same regex which is outputted, and as you can see again, its working.
What am I missing in my code ?