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:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...