如果找到至少 2 個分組詞,如何使量詞僅匹配?我需要這個來匹配: ((?i:\bjack\b)|(?i:\bjill\b)|(?i:\bjohn\b)){2,}我需要這個不匹配:Match if >= 2 of the words are found, in any order and case我該怎么做呢?幾個小時后,我厭倦了閱讀正則表達式。謝謝!
2 回答

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
你可以這樣做:
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.
或者,(\b(?i:jack|jill|john)\b.*){2,}做你想做的,我想。

呼啦一陣風
TA貢獻1802條經驗 獲得超6個贊
((jack.*)|(john.*)|(jill.*)){2,}
將匹配
杰克和吉爾上山了
杰克和約翰相愛了
吉爾和約翰破壞了理想的家
但不是為了
約翰深知反烏托邦的愿景
杰克在吃洋蔥
- 2 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消