[英]Regular expression: <?>?=?\d{4}: what does it match?
In a C# class, I came across this regular expression:在 C# class 中,我遇到了这个正则表达式:
<?>?=?\d{4}
It is pretty obvious that its last part ( \d{4}
) matches 4 decimal digits but what about <?>?=?
很明显,它的最后一部分(
\d{4}
)匹配 4 个十进制数字,但是<?>?=?
? ? What does it match?
它匹配什么?
Thanks for any explanations.感谢您的任何解释。
Four digits at the end preceded by the <
, >
and =
occurring zero or once in that order.末尾的四位数字前面是
<
、 >
和=
以该顺序出现零或一次。
Match:匹配:
<>=1234
>=1234
=1234
1234
<=1234
The expression '<?>?=?'
表达式
'<?>?=?'
matches a '<' char (or none) possibly followed by a '>' possibly followed by a '='.匹配一个 '<' 字符(或无字符),可能后跟一个 '>',可能后跟一个 '='。 Thus all of the following will match:
因此,以下所有内容都将匹配:
The question mark after the characters make it optional, so it matches any combination where each character can be present or not:字符后面的问号使它成为可选的,因此它匹配每个字符可以存在或不存在的任何组合:
It's probably meant to match any of the three characters on its own, but then you would rather use [<>=]?
它可能意味着单独匹配三个字符中的任何一个,但是您宁愿使用
[<>=]?
instead.反而。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.