C# RegEx problems - string to dictionary

Markus Freitag 3,791 Reputation points
2021-08-11T18:37:46.027+00:00

Hello,
I have this string. scanned=
[)>[RS]06[GS]PTVK1281257[GS]21P666[GS]11D201632[GS]Q60[GS]18VLMDM5[GS]1TAFJH0010-1[GS]13E5a[GS]1PW12R789B[GS]4LCN[GS][RS][EOT]]

122415-rege2.png

With.

 Dictionary<string, string> results =  
            Regex.Matches(scanned, @"(?i)\](\d*[A-Z])(.+?)\[").Cast<Match>().ToDictionary(m => m.Groups[1].Value, m => m.Groups[2].Value);  
  
            System.Diagnostics.Trace.WriteLine(scanned);  

Works not with

 [)>[RS]06[GS]PTVK1281257[GS]21P[GS]11D201632[GS]Q60[GS]18VLMDM5[GS]1TAFJH0010-1[GS]13E5a[GS]1PW12R789B[GS]4LCN[GS][RS][EOT]]  

122359-rege1.png

2P Prefix is wrong.

Can somebody help me, see the mistake for RegEx? Thanks in advance.
Problems, when the value is empty.

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2021-08-11T18:54:21.263+00:00

    Try another pattern:

    @"(?i)\](\d*[A-Z])(.*?)\["
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.