I have a HTML string and want to replace all links to just a text.
E.g. having
Some text <a href="http://google.com/">Google</a>.
need to get
Some text Google.
What regex should I use?
I have a HTML string and want to replace all links to just a text.
E.g. having
Some text <a href="http://google.com/">Google</a>.
need to get
Some text Google.
What regex should I use?
Several similar questions have been posted and the best practice is to use Html Agility Pack which is built specifically to achieve thing like this.
I asked about simple regex (thanks Fabrian). The code will be the following:
var html = @"Some text <a href="http://google.com/">Google</a>.";
Regex r = new Regex(@"\<a href=.*?\>");
html = r.Replace(html, "");
r = new Regex(@"\</a\>");
html = r.Replace(html, "");
var html = "<a ....>some text</a>";
var ripper = new Regex("<a.*?>(?<anchortext>.*?)</a>", RegexOptions.IgnoreCase);
html = ripper.Match(html).Groups["anchortext"].Value;
//html = "some text"