Regex Processing & Matching Validation Flowchart

%% Regex Parsing and Match Result Comparison Process flowchart TD Start["🔹 Start"] --> Step1_1["1.1 Split regex structure
(Using a special regular expression to match the target regex, decompose it into the following structures with a ratio of 1:1:1:1+:
▫️Prefix: Actual matching characters, anchors, group construct prefixes [(, (?>, (?=, etc.], inline comments, closing parenthesis ')','|'
▫️Quantifier 1: Basic quantifiers such as +, *, ?, {num1,num2}
▫️Quantifier 2: Lazy matching symbol '?'
▫️Comment: Inline comments, end-of-line comments, invalid whitespace (at least one empty comment as a separator)
"] Step1_1 --> Step1_2["1.2 Parse into custom syntax tree
(Traverse all decomposed structures to generate a structured syntax tree)
The following actions may be performed:
▫️Simplify quantifiers
▫️Move quantifiers after ignored whitespace, inline comments, and end-of-line comments
▫️Simplify redundant '|' in conditional expressions
▫️Cross-platform compatible conversion (Reference: Cross-platform compatibility issue)
"] Step1_2 --> Step_input{"Is there input to match?"} Step_input --> |Yes| Step2["2. Initialize input subscript
(Set txtpos = 0)"] Step_input --> |No| Step9["9. Return compressed results"] Step2 --> Step3["3. Infer new matches
(Start matching from txtpos)"] Step3 --> Step4{"4. Match successful?"} Step4 -->|Yes| Step5["5. Compare results with C# output
(Check Index and Length of all the captures of all groups)
(Why need two validation modes? Because sometimes the outputs of the two modes are inconsistent)"] Step5 --> Step6{"6. Is the current match length 0?"} Step6 -->|Yes| Step6a["txtpos += 1
(Avoid infinite loops)"] Step6 -->|No| Step6b["txtpos = end position of the current match"] Step6a & Step6b --> Step7{"7. txtpos > input.Length?"} Step7 -->|No| Step3 Step7 -->|Yes| Step8["8. Consistency check of the number of matches
(Compare the number of inferred matches with C# output, mark if inconsistent)"] Step4 -->|Failure| Step8 Step8 --> Step9 Step9 --> End["🔹 End"] %% Style definitions (consistent with the original example) classDef startEnd fill:#f0f8ff,stroke:#1976d2,stroke-width:2px,rounded:10px classDef process fill:#e8f5e9,stroke:#388e3c,stroke-width:1.5px,rounded:5px classDef decision fill:#fff3e0,stroke:#f57c00,stroke-width:1.5px,diamond:true %% Style binding (consistent with the original example) class Start,End startEnd class Step1_1,Step1_2,Step2,Step3,Step5,Step6a,Step6b,Step8,Step9 process class Step_input,Step4,Step6,Step7 decision