Reputation: 127
Is there an option in regex to tell how many from passed words in match must find ? I have regex:
/\b(brasserie|desbrosses)\b/
and string:
"brasserie desbrosses"
Now this regex find me two match, but i want to tell him how many words should it match to return positive result. So if i tell him return me positive match for 2 words and i will have string: "brasserie villa" it shouldn't return me positive match, because only one word match regex. So is there an option to do this ? and of course for other number of words, like 3, 4...
Upvotes: 0
Views: 99
Reputation: 784998
You can use:
(\b(?:brasserie|desbrosses)\b\s*){2}
to force match to succeed with at least 2 matches of given match words.
Upvotes: 1