I have some text data in this format:
MI
00
3
MD
1
0.0000
MD
2
0.0000
MD
3
0.0000
This block can be repeated and the number of MDs is variable (but always >= 1) and the numeric values following need to be captured for each one.
I have a regex that matches every MD per MI but it will only capture the last MD. Is it possible to capture each MD without knowing in advance how many there are?
EDIT: Per requests…
Regex is below; the important part of my question remains “can I capture every MD set?”
MI\r\d\d\r(\d)\r[\s\w]{6}\r(MD\r[\s\d]{2}\r[\s\d\.\-]*\r)+
My language of choice is C# but I’d take an answer in any language because it would at least give me a start.
MD is a data point out of a sulfur detector from the early 90s.
Every Match has a Groups collection. In your case Matches[0].Groups[1] would match the MD records, like “MD\n1\n0.0000MD\n2\n0.0000MD\n3\n0.0000”.
Every Group has a Captures collection, which you can iterate over to find all MD instances. This will give you one string per MD, so Matches[0].Groups[1].Captures[0] will be “MD\n1\n0.0000”.
EDIT: Although you’ve already accepted the answer, here’s a way to parse everything in a single go:
This is the test text I used:
The output is: