tags:

views:

42

answers:

2

I am attempting to extract all data from a file with one regex expression. Since there are optional(?,*) and repitious(*,+) expressions, it would be difficult to enumerate through the captures, at least in a readable and understandable fashion. Therefore, I am using named groups. However the data is in an XML like structure; neseted elements can have complex elements. So I am using nested name groups. However, one I have captured a group, how do I retrieve the nested groups by name?

Dim mtch = System.Text.RegularExpressions.Regex.Match(fullText, _
                                       "\s+(?<PolyID>\d+)" & _
                                       "\s+(?<Center>" & _
                                            "(?<LAT>\-?\d\.\d+E\+\d{2})" & _
                                            "\s+(?<LON>\-?\d\.\d+E\+\d{2})" & _
                                        ")\n(?<Point>\s+" & _
                                            "(?<LAT>\-?\d\.\d+E\+\d{2})" & _
                                            "\s+(?<LON>\-?\d\.\d+E\+\d{2})" & _
                                        "\n)+END\n", _
                                        System.Text.RegularExpressions.RegexOptions.Singleline)

I am trying to get the

mtch.Group("Center").Group("LAT").Value

How can I retrieve named subgroups of the current group?

A: 

Instead of using Regex, have you considered using XSLT? or XLinq?

Nescio
this is not an XML file. Its XML-Like, in the sense that nested elements (Groups) can have arbitrary complexity
Fragilerus
@Frag How exactly is the file structured?
NullUserException
The format of the data is their own proprietary format. It doesnt follow any standard convention. However, the data structure is reliable in the sense that it follow THEIR convention.
Fragilerus
A: 

I would suggest that you rename your groups to "CenterLAT", "CenterLON", "PointLAT", and "PointLON". You might be able to get what you want from the mtch.Groups("Center").Captures collection, but you can't index that collection by name.

Jim Mischel