Reputation: 15475
have the following text file:
<div>
<asp:HyperLinkField HeaderText="Hello World of Regular Expression" />
</div>
How do i get what's between the double quotes for any word and spaces?
Updated:
//This one gets me close but doesn't get me strings with spaces in them
var match = Regex.Match(tokens[1], @"HeaderText=\""(\w+)\""");
//This was suggested below. It shows correct match count but values are just empty strings
var match = Regex.Match(tokens[1], @"HeaderText=""[^""]+""|[\w]+");
if (match.Success)
{
yield return new KeyValuePair<string, string>(
file, match.Groups[1].Value //This is empty for 2nd scenario
);
}
Upvotes: 1
Views: 916
Reputation: 33149
Try this one:
"[^"]+"|[\w]+
This will return a list of matches, of the individual words AND the entire expression between quotes.
Upvotes: 2