希望 永远是快乐的.

有一种沉默叫霸气,有一种内敛叫个性,有一种简单叫深遂,有一种不屑叫自我。

导航

Get Images tag from the html string using C#

  1. To get all image tags from the html string using c#,
  public List<Uri> FetchLinksFromSource(string htmlSource)
        {
            List<Uri> links = new List<Uri>();
            string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
            MatchCollection matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            foreach (Match m in matchesImgSrc)
            {
                string href = m.Groups[1].Value;
                links.Add(new Uri(href));
            }
            return links;
        }
      

2. To verify the mail format using the regular expression

public static bool IsEmail(string str_Email)  
    {  
        return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");  
    }  
   

 

 

 

 

posted on 2013-05-02 17:44  希望(Jack)  阅读(289)  评论(0编辑  收藏  举报