How do I make quantifier only match if at least 2 of the grouped words are found?
I need this to match: ((?i:\bjack\b)|(?i:\bjill\b)|(?i:\bjohn\b)){2,}
And I need this to not match:
Match if >= 2 of the words are found, in any order and case
How do I go about doing that? After a few hrs I'm tired of reading regex. Thanks!
You could do:
re, _ := regexp.Compile(`\b(?i:jack|jill|john)\b`)
ma := re.FindAllString("Jill is friends with John. But Jack doesn't know.", -1)
if len(ma) < 2 //...then there aren't enough matches.
Alternatively, (\b(?i:jack|jill|john)\b.*){2,}
does what you want, I think.
((jack.*)|(john.*)|(jill.*)){2,}
will give a match for
jack and jill went up the hill
jack and john are in love
jill and john wreck the ideal home
but not for
john is privy to a dystopian vision
jack is eating onions