473,498 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Regular Expressions to replace HTML tags, except simple formatting

4 New Member
Hi,

I'm adding some old database fields to view in our new C# .NET system with cascading stylesheets, and unfortunately the old data has HTML formatting in there which I would like to be removed for these pages as this will be mainly driven by the CSS.

I know the Regular Expression to remove all HTML tags, but would anybody happen to know a regular expression that could replace all HTML tags except bold, italic, underline and breaking space (<b>,<u>,<i>,<br />) as I'd still like to give users the opportunity to use these tags?

Thanks,
Andi
Nov 24 '06 #1
1 2546
AndiSmith
4 New Member
If anyone's interested, I decided to use the following Pattern, which removes each HTML element explicitly except the ones I want:

Pattern = @"(<\/?)(?i:(?<element>a(bbr|cronym|ddress|pplet|rea)?|" + @"base(font)?|bdo|big|blockquote|body|button|c(apt ion|enter|ite|(o(de|l(group)?)))|" + @"d(d|el|fn|i(r|v)|l|t)|em|f(ieldset|o(nt|rm)|rame (set)?)|h([1-6]|ead|r|tml)|iframe|" + @"img|in(put|s)|sindex|kbd|l(abel|egend|i(nk)?)|m( ap|e(nu|ta))|no(frames|script)|o(bject|"+ @"l|pt(group|ion))|p(aram|re)?|q|s(amp|cript|elect |mall|pan|t(r(ike|ong)|yle)|u(b|p))|" +
@"t(able|body|d|extarea|foot|h|itle|r|t)|ul|var))( \s(?<attr>.+?))*>";
Nov 24 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11542
by: James Geurts | last post by:
Hi all Can someone help me out with a regex to remove all html tags except for <p>,</p>,<br>,<br/> from a string Thank Jim
11
3037
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
3
1611
by: Bryan | last post by:
Hi All: I'm trying to find the right Regexp string to remove empty SPAN tags from an HTML string. Say I have a string like so, and I want to remove the empty span tags: <span>This is my...
1
1684
by: Showjumper | last post by:
I need a regulr expression that cn be used to find <a> tags with the href attribute set to mailto:. I need to be to search out all the email addresses in the text of the pages in a website. So for...
8
388
by: P K | last post by:
I have an XML in which I have to comment out the <responseopt> tag the tags between this tag should not be commented I plan to use regular expressions The tags looks like this <responseopt...
3
2001
by: apiringmvp | last post by:
All, So I am creating a function that gets a short blurb of html from a blog. I would like to retain all html formating and images. The code below works well, with the exception of one issue....
2
1097
by: tshad | last post by:
I am trying to turn my html page into text only (except for <atags - links). I have changed everything except remaining tags. ************************************ // Remove remaining tags like...
0
1937
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
3
3258
by: Rob | last post by:
Hi, I need to convert our word documents to html for our website. I've used MS Word's "Save as HTML" feature and ran "Microsoft Office HTML Filtrer 2.0" to clean up the code but I am stuck with a...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.