Regular expression to get all the <a> </a> 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 (1)

  1. Oded says:

    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):

Skip to main content