0

I need to get the value Status. from this piece of xml:

string xml = "<value z:Id=\"8\" z:Type=\"System.String\" z:Assembly=\"0\">Status.</value>";

Regex regexFieldValue = new Regex("z:Assembly=\"0\">(?<fieldValue>[^<|\\.|.]+)</value>");

Match match = regexFieldValue.Match(xml);
if (match.Success)
{
    Group group = match.Groups["fieldValue"];
    return group.Value;
}

Tanks

vks
  • 67,027
  • 10
  • 91
  • 124
André Voltolini
  • 426
  • 8
  • 14
  • Your regex would be `"z:Assembly=\"0\">(?[^<>]+)"` – Avinash Raj Sep 26 '14 at 16:30
  • 1
    The usual advice is "Use a parser" because XML isn't a regular language. See http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Brian Sep 26 '14 at 16:31
  • Yeah, but XML parsers are so boring and easy to use. It's much cooler to write some incomprehensible regular expression. – Jim Mischel Sep 26 '14 at 16:53

2 Answers2

0

[^<|\\.|.]+ won't do as you expected. So change this to [^<>]+ in your regex.

z:Assembly=\"0\">(?<fieldValue>[^<>]+)</value>

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0
z:Assembly=\\"0\\">(?<fieldValue>(?:(?!<\/value>).)*)<\/value>

Try this.see demo.

http://regex101.com/r/lS5tT3/60

vks
  • 67,027
  • 10
  • 91
  • 124