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:

Regex obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...