string content="
<br /><br /><a href="need to replace this url">Cooking School</a><br /><br /><a href="http://www.sdlm.com">Feed your senses</a><br /><br /><a href="http://www.sdl.com">Take your cooking skills to the next level. Find a cooking school near you!</a><br /><br /><a href="http:google.com"><img src="http://www.sdlm1.com/autd3umrl_u_t.jpg" /></a>
"
I need to replace all anchor tags href value with different urls
I used the following function but its getting error
public List<string> GetLinksFromHtml(string content)
{
string regex = @"<(?<Tag_Name>(a)|img)[^>]*?(?<URL_Type>(?(1)href|src))s*=s*(?:""(?<URL>(?:""|[^""])*)""|'(?<URL>(?:\'|[^'])*)'))";
var matches = Regex.Matches(content, regex, RegexOptions.IgnoreCase | RegexOptions.Singleline);
var links = new List<string>();
foreach (Match item in matches)
{
string link = item.Groups[1].Value;
links.Add(link);
}
return links;
}
Thanks for any help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…