I want to write some code to parse a search string. My previous post shows my filter code thanks to Scraph. Now I need to handle the following search scenarios:
age>10age>=10items!=3
The following code detects if there's a number in the string:
if(queryValue.match(/\d+/g)) {
$log.debug("Regex detected numbers");
}
I've tested this and it works with an input like >=10. Now I need to extract the >= and apply that to my search. I can create an array or operators like so:
var operators = ['>', '>=', '<', '<=', "!="]
And then have a for loop to figure out which operator it is then extract the number portion and do the filtering. However that seems overly verbose so I'm wondering if there's a cleaner solution to my problem.