The URL query after a decodeURIComponent
and a split()
looks like this ["pcs_availability:Online", "price:[1500 TO 1999.99]"]
the results I am looking for is returning an array with the proper integer like [1999.99]
. But there can be more than 1 price range in URL query string for example ["pcs_availability:Online", "price:[250 TO 499.99]:[500 TO 999.99]:[1500 TO 1999.99]"]
. Which should return [499.99, 999.99, 1999.99]
. I forgot to mention that the price positioning in the array could be different depending on the other URL queries. So that it's not always going to be guaranteed to be in the same spot.
This was the approach taken.
const pattern = /^price:{1,2}\[.*? TO (.*)]$/;
const price = query
.map(q => {
const match = pattern.exec(q);
return match;
});
Which returns this. I tried modifying the regex but unfortunately I haven't been able to get the results that I am looking for.
["price:[250 TO 499.99]:[500 TO 999.99]:[1500 TO 1999.99]", "1999.99", index: 0, input: "price:[250 TO 499.99]:[500 TO 999.99]:[1500 TO 1999.99]", groups: undefined]