The syntax is {min,max}, where min is zero or a positive integer
number indicating the minimum number of matches, and max is an integer
equal to or greater than min indicating the maximum number of matches.
If the comma is present but max is omitted, the maximum number of
matches is infinite. So {0,1} is the same as ?, {0,} is the same as *,
and {1,} is the same as +. Omitting both the comma and max tells the
engine to repeat the token exactly min times.
没有任何意义。引擎将匹配它字面上,所以你的正则表达式失败。
使用
{}
内没有空格看看regex101.com怎么说:
您可以使用
{1,8}
限制量词,它将匹配1到8位数字。我知道至少有一个,因为您的原始regex中有+
。见demo
从regular-expressions.info:
{}
有三种形式:{N}
固定时间{M,}
至少M次{N,M}
持续N到M次。如果使用最后一个,则最小值是必需的。
将regex改为
\d{1,8}
以匹配1到8倍的数字从1开始,因为您正在使用+这是
{1,}
的快捷方式相关问题 更多 >
编程相关推荐