I am not sure what seems to be the issue but running exec() inside for loop in Javascript(Nodejs, Chrome console, Firefox console) is producing incorrect results. As far as I know, exec() is a synchronous method, called inside a synchronous loop which should produce the expected output.
const FILTER_REGEX = /(\w+)\s+(below|under|lesser than|lower than|above|over|more than|higher than|greater than|equals|equal to|same as|>|<|=)\s+(\d+)/gi;
const searchQuery = "Package Quantity > 50000 Date yearly ListPrice above 100";
const filterMatches = searchQuery.match(FILTER_REGEX) || [];
for(const filterMatch of filterMatches) {
const filterMatchGroups = FILTER_REGEX.exec(filterMatch);
console.log(`filterMatch: ${filterMatch}, filterMatchGroups: ${filterMatchGroups}`);
}
Currently, I am getting the following as output, sometimes filterMatchGroups for first string becomes null and gives filterMatchGroups for second one.
filterMatch: Quantity > 50000, filterMatchGroups: Quantity > 50000,Quantity,>,50000
filterMatch: ListPrice above 100, filterMatchGroups: null