贪婪量词的 ASP.Net 正则表达式问题
我有 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} 是“贪婪量词”,
但是有没有办法使用相同的字符串创建正则表达式,或者是否可以用其他字符替换这些贪婪量词?
我不想改变我的琴弦。
I have asp.net application where string is created in following way.
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).
I know the reason is because *, +, ?, {num, num} are "greedy quantifiers"
but is there any way to create RegEx using same string or is it possible to replace these greedy quantifiers with other characters?
I dont want to change my string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个字符串:
Try this string:
只需从正则表达式中删除
|*
或将其替换为|.*
但它没有任何意义。提示:使用 Regulator 进行正则表达式调试。Just remove
|*
from your regular expression or replace it with|.*
but it has no sense. Tip: use Regulator for RegEx debug.