Regex To Extract Attribute Value
What would be a quick way to extract the value of the title attributes for an HTML table: ... Proclo <
Solution 1:
This C# regex will find all title values:
(?<=\btitle=")[^"]*
The C# code is like this:
Regex regex = new Regex(@"(?<=\btitle="")[^""]*");
Match match = regex.Match(input);
string title = match.Value;
The regex uses positive lookbehind to find the position where the title
value starts. It then matches everything up to the ending double quote.
Solution 2:
Use the regexp below
title="([^"]+)"
and then use Groups to browse through matched elements.
EDIT: I have modified the regexp to cover the examples provided in comment by @Staffan Nöteberg
Post a Comment for "Regex To Extract Attribute Value"