次の方法で共有


Regular expression to get all the link tags and there value from a string

 

hrefLink = "This text will have html + text + a link attribute "; \\ The below code will get you the content from <a> till </a>.

MatchCollection m = Regex.Matches(hrefLink, @"(<a.*?>.*?</a>)",RegexOptions.Singleline);

foreach(Match m1 in m){string value = m1.Groups[1].Value;}

Comments

  • Anonymous
    September 29, 2011
    Good approach if you know that the input HTML will not vary much. However, HTML is not a regular language, so if parsing HTML from many different sources, RegEx is a poor choice. See this StackOverflow thread (in particular the selected answer): stackoverflow.com/.../1583