The following returns the original string without the the value of targetForRemoval
removed:
let targetForRemoval = "https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_includes"
let testing = "Why will you not remove the following url https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_includes from this string?"
testing = testing.replace(targetForRemoval, "");
console.log(testing); // Still includes the url
In addition to the standard string replace i have also tried it with regex:
let regExp = new RegExp(targetForRemoval);
testing = testing.replace(regExp, "");
In testing i did notice that when i remove the ?
from the url, the replace method works, but this is obviously not a solution.
Can anyone explain why the ?
breaks the replace method?