Find first item inside angular brackets after occurrence of other item, using RegEx, in C#
- by Mihaela
I have an xml-like text, in which I would like to find the item that occurs in the first occurrence of a certain pattern:
typically:
...
<PropertyGroup><name>true</name></PropertyGroup><PropertyGroup>....
....
Could also be
...
<PropertyGroup>
<name>
true</name>
</PropertyGroup>
...
<PropertyGroup>
...
In the above, I need to extract the "name".
My initial assumption was that all occurrences were to be in one line, and I wrote my code using string properties, but it is very difficult o take in consideration every possibility, and only RegEx can save me.
I just don't know how to write it...
I Have started with something like this:
Regex regex = new Regex("(?<=<PropertyGroup>#)<+");
Match matches = regex.Matches(Text)[0];
MessageBox.Show(matches.ToString());
I think this finds the first item after a <PropertyGroup>, but I don't know how to make it get the item within the angular brackets... (which may be after one or more newlines, and/or spaces).
I know that there are utilities for parsing xml, but I am looking for something simple to insert in a c# program
Can someone please help me ? Thank you very much.