开发者

Help interpreting a regular expression

My skills at interpreting regular expressions are a bit rusty. Can someone help me with this one?

^[V0-9]?\d{2}(\.\d{1,2})? 

I know the first expressions says that the start of the string begins with the character V or a digit. But then I have trouble interpreting the rest. What does the first "?" mean? I know \d{2} means a two character digit string. But what does it mean in the context of the preceding "?". Then is the expression in the parentheses meaning that optionally there is a two digit chara开发者_高级运维cter string preceded by a "."?


^[V0-9]?

String starts with an optional single character that's either V or a digit (that is, the first ? pertains to the [V0-9]).

\d{2}

... followed by exactly two digits

(\.\d{1,2})?

... followed by an optional sequence/subpattern consisting of

\.\d{1,2}

... a single period (.) followed by either 1 or 2 digits.

That means, yes, your interpretation

Then is the expression in the parentheses meaning that optionally there is a two digit character string preceded by a "."?

is correct (almost).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜