I am trying to figure out a regex which matches the following conditions in a query parameter. I need to find if the text has an and or or operator passed in the query parameters. I can have a URI like http:$URL/$RESOURCE?$filter="firstName eq 'John' and tenantId eq '32323232'"&$order="asc.
Text 1: firstName eq 'John' and tenantId eq '32323232'
Text 2: firstName like 'J%' or companyName eq 'IBM'
Text 3: companyName like 'John and Sons'
While the following regex pattern does work for Text 1 and Text 2, however I need a way to filter out Text 3, since the and here comes inside a value. Values shall always be in quotes, so any and or or values in quotes should be ingored by regex. Any help to filter out cases like Text 3 shall be appreciated. Thanks
public static boolean hasANDorORoperator(String filter) {
return filter.matches("^(.*?)\\s+(?i)(or|and)\\s+(.*?)$");
}