Skip to content

Commit

Permalink
Keep quantifiers with their capture groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sblom committed Dec 20, 2023
1 parent c66401b commit ed80c9f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions RegExtract/RegexCaptureGroupTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ private RegexCaptureGroupNode BuildCaptureGroupTree(ref int loc, ref int num, in
else
{
if (myname == "0") throw new Exception("Too many close parens.");
if (loc + 1 < _regexString.Length)
{
if (_regexString[loc + 1] is '?' or '+' or '*')
{
loc++;
if (loc + 1 < _regexString.Length && _regexString[loc + 1] is '?')
loc++;
}
else if (_regexString[loc + 1] is '{')
{
var startloc = loc;
// TODO: The actual regex grammar will bag out of this if the quantifier doesn't actually parse.
while (loc < _regexString.Length && _regexString[loc] is not '}')
{
loc++;
}
if (loc >= _regexString.Length || _regexString[loc] is not '}')
{
loc = startloc;
}
else if (loc + 1 < _regexString.Length && _regexString[loc + 1] is '?')
loc++;
}
}
return new RegexCaptureGroupNode(myname, children.ToArray(), ((start, loc - start + 1),_regexString.Substring(start, loc - start + 1)));
}
case '[':
Expand Down

0 comments on commit ed80c9f

Please sign in to comment.