Find first item inside angular brackets after occurrence of other item, using RegEx, in C#
Posted
by
Mihaela
on Stack Overflow
See other posts from Stack Overflow
or by Mihaela
Published on 2012-11-11T22:36:37Z
Indexed on
2012/11/11
23:00 UTC
Read the original article
Hit count: 360
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.
© Stack Overflow or respective owner