I would love to use the String.replace() function in JavaScript to replace a certain portion of a first string with some non deterministic user input (second string)
Example 1:
> var userinput = "^fancy $& regexlike stuff $/i"
> "some @@include test".replace(/@@include/, userinput)
"some ^fancy @@include regexlike stuff $/i test"
should be
> var userinput = "^fancy $& regexlike stuff $/i"
> "some @@include test".replace(/@@include/, userinput)
"some ^fancy $& regexlike stuff $/i test"
Example 2:
> var userinput = "^fancy $& regexlike stuff $/i"
> "some @@include test".replace(/@@include/, userinput)
"some ^fancy & test"
should be
> var userinput = "^fancy &$ regexlike stuff $/i"
> "some @@include test".replace(/@@include/, userinput)
"some ^fancy &$ regexlike stuff $/i test"
So here is the actual question:
How do I tell String.replace() to ignore all regex syntax given in its second argument userinput? Is there any sanatize flag or so?
Thank you verymuch in advance!