我有这种情况,数字 20 在一行中重复三次:
20 20 20 7 27
和
20 20 7 27 20 19
我想找到这种数字 20 重复三次的线。
我制作了一个正则表达式,但必须稍微改进一下:
搜索:\b(\d+)\b.*?\1{3}
答案1
这正好匹配了 3 次数字20
:
- Ctrl+F
- 找什么:
^(?:(?!\b20\b).)*(?:\b20\b(?:(?!\b20\b).)*){3}$
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Find All in Current Document
解释:
^ # beginning of line
Tempered greedy token
(?: # non capture group
(?!\b20\b) # negative lookahead, make sure we haven't 20
. # any character but newline
)* # end group, may appear 0 or more times
(?: # non capture group
\b20\b # number 20, the word boundaries are mandatory to not match 120 or 205
Tempered greedy token
(?: # non capture group
(?!\b20\b) # negative lookahead, make sure we haven't 20
. # any character but newline
)* # end group, may appear 0 or more times
){3} # end group, must appear 3 times
$ # end of line
我想要匹配包含以下内容的行至少3 倍的数字20
,使用:
^.*(?:\b20\b.*){3}$