[Solved] Regex Conditions C# [closed]


I’m not sure if there is a way to short-circuit the Regex engine that way. You can use the control verbs (*FAIL) to immediately fail a match or (*LIMIT_MATCH=x) to limit the number of matches you receive to a specific quantity, but I don’t believe there’s a way to dynamically tell the engine to just stop matching entirely on reaching a specific condition.

(Note: According to Wiktor Stribizew in the comments, .NET’s Regex engine does not actually support control verbs, so consider the previous paragraph an exercise in general theory.)

What you can do instead is to get all the matches of numbers preceded by spaces like so:

var matches = Regex.Matches(input, @" +[\d.-]+");

Then loop through them to see if the number of leading spaces is exactly 37:

foreach (Match match in matches)
{
    if (match.Value.Count(c => c == ' ') != 37)
        break;

    // continue processing
}

6

solved Regex Conditions C# [closed]