We have a JAVA String as
String str = "WHERE geoAreaName=\"Barcelona (Spain) EUR\" AND (startDate=\"2019-01-01\" AND endDate=\"2020-01-01\")";
We need to remove characters like [ , ], ( , ), { , }
from it.
The regex pattern to identify the same is : [\\[\\](){}]
So on executing below code, the output is:
System.out.println(str.replaceAll("[\\[\\](){}]" , ""));
>>> WHERE geoAreaName="Barcelona Spain EUR" AND startDate="2019-01-01" AND endDate="2020-01-01"
This works fine, except we need to keep the data enclosed in double quotes intact.
Barcelona (Spain) EUR
needs to be intact and not converted to Barcelona Spain EUR
The expected output is :
WHERE geoAreaName="Barcelona (Spain) EUR" AND startDate="2019-01-01" AND endDate="2020-01-01"
So in a nutshell, I need a regex which will identify the characters in given string except for the parts which are in quotes.
Any help is appreciated.