I need to be able to strip out a condition in a string, here it is:
(("${Operation}" == "Fixed") && ("-" == "-"))
I’d like to be able to replace "${Operation}" == "Fixed" with "" or anything between () that has ${} in it. In other words if there is ${} on the left hand side of the condition I want to get rid of the condition entirely.
In general, a regular expression is not the right approach here. There are lots of cases that are valid JavaScript syntax, but that won’t fit nicely into a regular expression. However, here’s one way to do it:
That only handles double quotes. If you need to handle both types of quotes, the expression will be more complicated. If you need to handle both types of quotes and your strings might contain quotes, then a regular expression really isn’t going to work.
If you can think of a different way to solve this problem, then you should. For example – where does the string come from? Can you get the data in a different format?
Also, it sounds like you’re setting this string up for a call to
eval. That’s a bad idea if it contains any kind of user input.