Thursday, June 26, 2014

Regular expression to find src attribute value of img tag

This regex is very handy when we want to parse html tags and use them in our code

Regex reSrc = new Regex(@"src=(?:(['""])(?<src>(?:(?!\1).)*)\1|(?<src>[^\s>]+))", RegexOptions.IgnoreCase | RegexOptions.Singleline);

Match mSrc = reSrc.Match(htmlImageTag);

if (!string.IsNullOrEmpty(mSrc.Groups["src"].Value))
{
         string imageUrl = mSrc.Groups["src"].Value;
}



Refer:http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_23964786.html

No comments:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...