Tim*_*ker 49
\b(\d)\1+\b
Run Code Online (Sandbox Code Playgroud)
说明:
\b # match word boundary
(\d) # match digit remember it
\1+ # match one or more instances of the previously matched digit
\b # match word boundary
Run Code Online (Sandbox Code Playgroud)
如果1还应该是有效匹配(零重复),请使用a *而不是+.
如果你还想允许更长的重复(123123123)使用
\b(\d+)\1+\b
Run Code Online (Sandbox Code Playgroud)
如果正则表达式应该应用于整个字符串(而不是在更长的字符串中查找"重复数字"),请使用开始和结束行锚点而不是\b:
^(\d)\1+$
Run Code Online (Sandbox Code Playgroud)
编辑:如何匹配完全相反的,即不是所有数字都相同的数字(除非整个数字只是一个数字):
^(\d)(?!\1+$)\d*$
^ # Start of string
(\d) # Match a digit
(?! # Assert that the following doesn't match:
\1+ # one or more repetitions of the previously matched digit
$ # until the end of the string
) # End of lookahead assertion
\d* # Match zero or more digits
$ # until the end of the string
Run Code Online (Sandbox Code Playgroud)
SLa*_*aks 10
要匹配单个数字的重复次数,您可以编写([0-9])\1*.
这匹配[0-9]到一个组,然后匹配该组的0或更多次重复(\1).
您可以编写\1+以匹配一个或多个重复.
| 归档时间: |
|
| 查看次数: |
40066 次 |
| 最近记录: |