简体   繁体   English

正则表达式最小长度

[英]Regular Expression Minimum Length

This will eventually be part of a larger expression but I've reduced it down to a much simpler form here (ie, there will be a true possibility of 40 characters instead of the 19 possible here). 这最终将成为更大表达式的一部分,但我已将其简化为更简单的形式(即,将有40个字符的真实可能性,而不是这里可能存在的19个字符)。 Given the following input: 鉴于以下输入:

;123?T

I get a successful match against this regex: 我与这个正则表达式成功匹配:

^(?:;(\d{0,19})\?.){1,40}$

However, I do not get a match against this regex: 但是,我没有得到这个正则表达式的匹配:

^(?:;(\d{0,19})\?.){3,40}$

The only thing I'm changing is the minimum length, both of which the input should satisfy. 我唯一要改变的是最小长度,输入应该满足这两个长度。 Why does the first one find a match and the second one doesn't? 为什么第一个找到匹配而第二个找不到? Maybe I'm just not understanding this quantifier but I thought it was simply {MIN, MAX}. 也许我只是不理解这个量词,但我认为它只是{MIN,MAX}。

Also, I have tested this in both of the following online testers: 另外,我在以下两个在线测试人员中测试了这个:

regular-expressions.info regular-expressions.info

regexpal.com regexpal.com

With the first part of the expression ^(?:;(\\d{0,19})\\?.) you are matching all of this ;123?T . 使用表达式的第一部分^(?:;(\\d{0,19})\\?.)你匹配所有这些;123?T

With the next part of the expression {1,40} you are saying match the above 1 through 40 times. 对于表达式{1,40}的下一部分,您要说的是匹配上述1到40次。 Notice that if you try to match ;123?T 3 times in a row, this obviously will not work, and that is the case when you say {3,40} . 请注意,如果您尝试匹配;123?T连续3次,这显然不起作用,当您说{3,40}时就是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM