How To Extract The Node Name In The Self-Closing Tags Using Regular Expressions In C#
Hello,
Here's the pattern matching of several self-closing XML tags.
In one of the parser that I made, I need to extract the node name which is in a self closing XML tag as part of the requirement for the output. In order to do that, you need to combine a positive lookbehind for the lesser than symbol (?<=<) and positive lookahead for the forward slash and greater than symbol (?=/>). And then perform a greedy search in between those groups. The complete pattern for that is presented on the code snippet below.
var NodeValue = Regex.Match(lstTempNodes[i], @"(?<=<)(.*)(?=/>)").Value.Trim();
Comments
Post a Comment