Lets say I have a string of words and phrases like this.
var a = "Apple Book \"Grand Piano\" Piano";
And I have a few variables like this.
var b = "Piano";
var c = "Grand Piano";
How do I remove variable b or c from string a. Currently i've been using javascripts replace method like this.
a = a.replace(b,"")
The problem with this is that it will remove the word Piano from the phrase "Grand Piano" when I only want it to remove the word Piano outside the quotes. I've been trying to use RegExp to get to some sort of solution but have been unable to figure it out. I was thinking I could possibly split the string up into an array and then compare the variables a/b in a for loop and then remove where they match and then put the string back together, not sure if that would be the best way. If someone could guide me in the right direction i'd be very gratefull.
Thank you.