Resources /
Programming / Find Quoted String Regular Expressions
Find A String Between Quotes With Regular Expressions
I must have written this regular expression many times, but each time I go back to it it seems like I have to search through Google for help on regular expressions - their syntax is so obtuse.
This expression finds the string between double quote marks after an XML attribute.
string contents = " CodeFile=\"abc\" ";
Match filenameMatch = Regex.Match(contents, "CodeFile=\"(?<CodeFile>[^\"]*)\"");
if (filenameMatch.Success)
{
//returns abc
filename = filenameMatch.Groups["CodeFile"].Value;
}