I have a string that contains html. I want to get all href value from hyperlinks using C#.
Target String
<a href="~/abc/cde" rel="new">Link1</a>
<a href="~/abc/ghq">Link2</a>
I want to get values “~/abc/cde” and “~/abc/ghq”
I have a string that contains html. I want to get all href value
Share
Using a regex to parse HTML is not advisable (think of text in comments etc.).
That said, the following regex should do the trick, and also gives you the link HTML in the tag if desired: