Convert HTML To Plain Text By RegularExpressions

This is my first post in this blog. I hope you find useful.
One of common problem for web developers is "converting html text to plain text".
in example : in search operations or sending plain text emails by newsletter and .....
in this post i do that with RegularExpressions.

  // Return Plain Text
  private string ConvertHtmlToPlainText(string htmlText)
  {
          return System.Text.RegularExpressions.Regex.Replace(htmlText, "<[^>]*>", string.Empty);
  }

The function is pretty simple but very useful in most situations.

Have Fun!
Published Sunday, June 29, 2008 12:43 PM by mlife

Comments

# .Net Convertir Html a Plain Text usando expresiones regulares

Pingback from  .Net Convertir Html a Plain Text usando expresiones regulares

# re: Convert HTML To Plain Text By RegularExpressions

Friday, April 03, 2009 9:25 AM by Chano Zamora

good post and useful!

# re: Convert HTML To Plain Text By RegularExpressions

Wednesday, September 16, 2009 2:23 AM by sreekar

Thank You

# re: Convert HTML To Plain Text By RegularExpressions

Wednesday, September 23, 2009 4:18 AM by miteshsura

hello,

so simple yet so useful , I was going to write my own method for this.. saved some time .

# re: Convert HTML To Plain Text By RegularExpressions

Thursday, November 19, 2009 4:45 AM by tont

I wouldn't call this 'converting to text'. More suitable term would be 'stripping html tags'.

Leave a Comment

(required) 
(required) 
(optional)
(required)