Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
贪心量词的ASP.Net正则表达式问题_Asp.net_Regex_Quantifiers - Fatal编程技术网

贪心量词的ASP.Net正则表达式问题

贪心量词的ASP.Net正则表达式问题,asp.net,regex,quantifiers,Asp.net,Regex,Quantifiers,我有一个asp.net应用程序,其中字符串是按以下方式创建的 string abc; abc="vindo|vindo|vind?40|vind?40|vincent van uden|vilm|vilm|slim?new|compas|*|darkc?loud"; Regex ABCRegex = new Regex(abc); but It throws error. at System.Text.RegularExpressions.RegexParser.ScanRegex()

我有一个asp.net应用程序,其中字符串是按以下方式创建的

string abc;
abc="vindo|vindo|vind?40|vind?40|vincent van uden|vilm|vilm|slim?new|compas|*|darkc?loud";

Regex ABCRegex = new Regex(abc);

but It throws error.
   at System.Text.RegularExpressions.RegexParser.ScanRegex()
   at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, Boolean useCache).
我知道原因是因为*,+,?,{num,num}是“贪婪的量词”

但是有没有办法使用相同的字符串创建正则表达式,或者用其他字符替换这些贪婪的量词


我不想更改字符串。

只需从正则表达式中删除
*
,或将其替换为
.*
,但它没有意义。提示:用于正则表达式调试。

尝试以下字符串:

abc = @"vindo|vindo|vind?40|vind?40|vincent van uden|vilm|vilm|slim?new|compas|\*|darkc?loud";

为了确认,我添加了
@
“\”
。在你的代码中添加了这两个之后,我没有得到一个例外。这与贪婪无关,只是你有一个量词(
*
)不能量化任何东西。如果您想匹配一个literal
*
,您需要对其进行转义,如@Aziz所示。