Let’s say we have this whitelist: one two three. And this blacklist: four five. Then:
three one twois a matching text (contains all whitelist words);one three two sixis a matching text (contains all whitelist words);two oneis not a matching text (lacks a whitelist wordthree);one four two threeis not a matching text (contains a blacklist wordfour).
Is there a regex solution to this problem?
This is not something you’d want to use a regex for. Better do it like this (example in Python):
You can do it, though:
^anchors the search at the start of the string.(?=...)ensures that its contents can be matched from the current position(?!...)ensures that its contents can’t be matched from the current position\bone\bmatchesonebut notlonely.So you get: