Donate

How To Extract The Node Name In The Self-Closing Tags Using Regular Expressions In C#

Hello,

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();
Here's the pattern matching of several self-closing XML tags.
Get The Node Name In The Self-Closing Tags Using Regular Expressions

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input