5

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). 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}.

Also, I have tested this in both of the following online testers:

regular-expressions.info

regexpal.com

4

1 回答 1

8

With the first part of the expression ^(?:;(\d{0,19})\?.) you are matching all of this ;123?T.

With the next part of the expression {1,40} you are saying match the above 1 through 40 times. 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}.

于 2013-06-13T22:05:02.163 回答