I wish to test string match with some conditions
Condition: All keys must be present.
RegExp: ^(?=.*key1)(?=.*key3)(?=.*key2)
Text: rer key1 werjk key2 and key2 and key3 and end
Text matched!
And now my questions:
- How can I test string to match any two keys out of three?
- How can I test string to match any one key out of three?
This is not trivial to solve in a single regex. Well, it is trivial for the simple examples you showed, but it won’t scale because you need to do the possible permutations yourself.
Two out of three (written in verbose mode for “readability”:
One out of three: