Besides that you should'nt parse HTML with regex, I'd go for
\(\"(.+)\"\)
as your regex. Simply extract anything between ("
and ")
.
For example:
string strRegex = @"\(\""(.+)\""\)";
Regex myRegex = new Regex(strRegex, RegexOptions.None);
string strTargetString = @"<link href=""<%= Page.ResolveClientUrl(""~/Styles/CAR.css"") %>"" rel=""stylesheet"" type=""text/css"" />";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
// Add your code here
}
}
(example code taken from http://regexhero.net/tester/)
If there will be only one occurence of <link href=""<%= Page.ResolveClientUrl(""~/Styles/CAR.css"") %>"" rel=""stylesheet"" type=""text/css"" />
or you want to get only the first occurence, then you can get rid of the for-loop and use:
string strRegex = @"\(\""(.+)\""\)";
Regex myRegex = new Regex(strRegex, RegexOptions.None);
string strTargetString = @"<link href=""<%= Page.ResolveClientUrl(""~/Styles/CAR.css"") %>"" rel=""stylesheet"" type=""text/css"" />";
Match myMatch = myRegex.Match(strTargetString);
The difference here is using Regex.Matches(string)
(which returns a MatchCollection
; every matched occurence) vs Regex.Match(string)
(which returns a single Match
; the first matched occurence only).