I have an XML file containing one (or more) key/value pairs. For each of these pairs I want to extract the value which is a two-byte hex value.
So the XML contains this snippet:
<key>LibID</key><val>A67A</val>
Which I can match using the following expression, with the ID in parenthesis.
Match match = Regex.Match(content, @"<key>LibID</key><val>([a-fA-F0-9]{4})</val>"); if (match.Success) { Console.WriteLine("Found Match for {0}\n", match.Value); Console.WriteLine("ID was {0}\n", "Help me SO!"); }
How can I change the last part so it returns the ID from the match?
I think you want
(As Dillie-O points out in the comments, it’s group 1 because group 0 is always the whole match.)
Short but complete test program:
Output: