I am working with a string variable named myString that includes some unwanted content towards the end:
var myString = 'The sentence is good up to here foo (bar1 bar2)';
var toBeRemoved = 'foo (bar1 bar2)';
I am looking for the best way to utilize JavaScript regex to remove the undesired portion. I have encountered an issue when using the replace() method due to the presence of parentheses.
Edit:
After taking Matthew's suggestion and attempting to escape the parentheses, it initially appeared unsuccessful. However, upon trying again, it worked as intended.
var myString = 'The sentence is good up to here foo (bar1 bar2)';
var toBeRemoved = 'foo (bar1 bar2)';
document.write(myString .replace(/foo \(bar1 bar2\)/i, ''));
Thank you, Matthew.