什么是"嵌套量词"为什么是这导致我的正则表达式失败? [英] What is a "Nested Quantifier" and why is it causing my regex to fail?
本文介绍了什么是"嵌套量词"为什么是这导致我的正则表达式失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的正则表达式我建立和正则表达式的好友进行测试。
I have this regex I built and tested in regex buddy.
"_ [ 0-9]{10}+ {1}+[ 0-9]{10}+ {2}+[ 0-9]{6}+ {2}[ 0-9]{2}"
当我使用这个在.net C#
When I use this in .Net C#
我收到异常
"parsing \"_ [ 0-9]{10}+ +[ 0-9]{10}+ +[ 0-9]{6}+ [ 0-9]{2}\" - Nested quantifier +."
这是什么错误呢?显然,.NET并没有像前pression。
What does this error mean? Apparently .net doesn't like the expression.
下面是正则表达式的哥们,这样你们能理解我的意图与正则表达式...
Here is the regex buddy so u can understand my intention with the regex...
_ [ 0-9]{10}+ {1}+[ 0-9]{10}+ {2}+[ 0-9]{6}+ {2}[ 0-9]{2}
Match the characters "_ " literally «_ »
Match a single character present in the list below «[ 0-9]{10}+»
Exactly 10 times «{10}+»
The character " " « »
A character in the range between "0" and "9" «0-9»
Match the character " " literally « {1}+»
Exactly 1 times «{1}+»
Match a single character present in the list below «[ 0-9]{10}+»
Exactly 10 times «{10}+»
The character " " « »
A character in the range between "0" and "9" «0-9»
Match the character " " literally « {2}+»
Exactly 2 times «{2}+»
Match a single character present in the list below «[ 0-9]{6}+»
Exactly 6 times «{6}+»
The character " " « »
A character in the range between "0" and "9" «0-9»
Match the character " " literally « {2}»
Exactly 2 times «{2}»
Match a single character present in the list below «[ 0-9]{2}»
Exactly 2 times «{2}»
The character " " « »
A character in the range between "0" and "9" «0-9»
在短...
什么是嵌套量词?
推荐答案
.NET的抱怨 +
在 {N}
风格的量词,因为它没有任何意义。 {N}
表示正好给定组正赛。 +
表示匹配一个或多个特定组。删除 +
的,它会编译罚款。
.NET is complaining about the +
after the {n}
style quantifier as it doesn't make any sense. {n}
means match exactly n of a given group. +
means match one or more of a given group. Remove the +
's and it'll compile fine.
"_ [ 0-9]{10} {1}[ 0-9]{10} {2}[ 0-9]{6} {2}[ 0-9]{2}"
这篇关于什么是"嵌套量词"为什么是这导致我的正则表达式失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文