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

发布于 2024-12-17 16:13:01 字数 587 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏月而来 2024-12-24 16:13:01

试试这个字符串:

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

Try this string:

abc = @"vindo|vindo|vind?40|vind?40|vincent van uden|vilm|vilm|slim?new|compas|\*|darkc?loud";
也只是曾经 2024-12-24 16:13:01

只需从正则表达式中删除 |* 或将其替换为 |.* 但它没有任何意义。提示:使用 Regulator 进行正则表达式调试。

Just remove |* from your regular expression or replace it with |.* but it has no sense. Tip: use Regulator for RegEx debug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文