ASP.Net Regular Expression issue for greedy quantifiers
-
07-03-2021 - |
سؤال
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.
المحلول
Try this string:
abc = @"vindo|vindo|vind?40|vind?40|vincent van uden|vilm|vilm|slim?new|compas|\*|darkc?loud";
نصائح أخرى
Just remove |*
from your regular expression or replace it with |.*
but it has no sense. Tip: use Regulator for RegEx debug.
لا تنتمي إلى StackOverflow