GibbsUSA.net Blogs  

Tuesday, February 07, 2012

 Logon   Back to Blog   Blogs Home   GibbsUSA.net Home  


Archives
 Home... 
 May 2008 (1) 
 August 2007 (2) 
 December 2006 (1) 
 October 2006 (5) 
 

Leave your comments...

10/26/2006 4:47 PM: Remove HTML tags using Regular Expressions

Recently I needed to remove specific HTML tags from a string obtained from a database. The use of Regular Expressions made this a single line of code using the Replace functionality:

string output = Regex.Replace(input, @"</?(?i:meta|embed|script|frameset|frame|iframe|object|link)(.|\n)*?>", ""); 
This code removes the following HTML tags:

meta
embed
script
frameset
frame
iframe
object
link

As you can see, this is easily changed to reflect any tags that you may want removing!

God I love those Regular Expressions!!!
Print >>> EMail >>>

Comments:
Please log on to the GibbsUSA site to post comments...

 

Join Chris on Facebook 
CLR v2.0.50727.3625


Please see the site Terms And Conditions and the site Privacy Statement.
This entire web site (and the software contents therein) is Copyright © Chris Gibbs 2000-2012.
Any reproduction or copying is expressly forbidden without the prior consent of Chris Gibbs.
For more information, please contact the site WebMaster (WebMaster@GibbsUSA.net).