In the end, I used a different approach. Maybe I just don't get the other solutions correctly, but it seems to me that there is no way to say which target words belong to which key.
If location: London, New York tags: Bar, Club
will switch to tags: Bar, Club location: London, New York
how would I now, which target words belong to location
and which tags
?
So, I did this:
var locationMatch = searchString.match(/location:(((?!tags:)[-A-Za-z0-9, ])+)/); //locationMatch[1] are the target words for "location" var tagsMatch = searchString.match(/tags:(((?!location:)[-A-Za-z0-9, ])+)/); //tagsMatch[1] are the target words for "tags"
I assume there is a simpler approach, but I am far from being regex pro.
source share