I'm studying RegEx patterns for use in C# and I'm trying to find out if a subgroup scenerio is possible. I'm parsing an INI file and I'd like to return a single matches collection that contains the section, key, and value information for each entry. Here's what I have for patterns so far:
Full Section Text: (?isx-mn)\[.*?(?=\[|\z)
Section Label (Named): (?<Section>\[.*\])
Key-Value Pairs (Named): (?<Key>.*)\s*=\s*(?<Value>.*)(?=\r)
What I can't figure out is how to create a pattern that will return a collection relating the key-value pairs to the section. Since a section can contain several key-value pairs (essentially, a one-to-many relationship), I'm not even sure this can be accomplished with a single pattern.
The results I'm hoping to acheive is a flat structure:
[Section][Key][Value]
[Section][Key][Value]
...
If anyone has done this type of grouping before, or feels up to the challenge, I would definately appreciate the help.
BTW, if you use RegEx and you haven't tried Expresso yet, you might want to check it out. It's a great (free) tool for evaluating expressions.
- Glen
Full Section Text: (?isx-mn)\[.*?(?=\[|\z)
Section Label (Named): (?<Section>\[.*\])
Key-Value Pairs (Named): (?<Key>.*)\s*=\s*(?<Value>.*)(?=\r)
What I can't figure out is how to create a pattern that will return a collection relating the key-value pairs to the section. Since a section can contain several key-value pairs (essentially, a one-to-many relationship), I'm not even sure this can be accomplished with a single pattern.
The results I'm hoping to acheive is a flat structure:
[Section][Key][Value]
[Section][Key][Value]
...
If anyone has done this type of grouping before, or feels up to the challenge, I would definately appreciate the help.
BTW, if you use RegEx and you haven't tried Expresso yet, you might want to check it out. It's a great (free) tool for evaluating expressions.
- Glen