473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Regex expression to remove some html tags

Hi,

Does anyone have a good regex expression to remove some html tags that
would be efficient in .Net. Basically I want to keep anchors, bolds and
a few others, so an expression that says remove all tags except these
few would be best.

Thanks.

Jan 3 '06 #1
3 2139
Just wiped this together, its may need some work.

string expres = @"<(?![!/]?[ABIU][>\s])[^>]*>";

string output = Regex.Replace(inputStr, expres, "", RegexOptions.IgnoreCase
| RegexOptions.Multiline);
Jan 3 '06 #2
Was tested using

<html>
<body>
<a name="top">
<b>My Website</b><br><br>
Here is the text for my website.
<table border="0" cellpadding="0">
<tr>
<td>Cell 1</td>
</tr>
<tr>
<td>Cell 2</td>
</tr>
</body>
</html>

you will still have to go through and replace /r/n s
Jan 3 '06 #3
Thanks Ben, I'll give it a whirl.

Jan 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: G. Stewart | last post by:
The objective is to extract the first n characters of text from an HTML block. I wish to preserve all HTML (links, formatting etc.), and at the same time, extend the size of the block to ensure...
2
by: JKJ | last post by:
I need help with a regular expression that will pull the title and all the meta tags held in the head section of an HTML file (including the head tags). I want to exclude everything else such as...
3
by: Senna | last post by:
Hi all, Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre> excluded). <pre> <tr> <td valign="top" align="right" class="SgSVT1BG" nowrap style=" padding-right: 6px "><div...
3
by: Hero41Day | last post by:
Hi, I'm looking for a easy simple way, using Regular expression to remove any dangerous HTML from user posts which might put other users at risk. right now i'm using this regular expression:...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
5
by: GS | last post by:
what is a good regex expression for remove html <img ....tag? I tried "<img *\->", RegexOptions.IgnoreCase) but it is not quite working thank you for your time
10
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a...
2
by: Shawn B. | last post by:
Greetings, Lets say I have the following expression: (<A|ABBR|ADDRESS|APPLET(\s){1,}(.*?)>(.*?)</A|ABBR|ADDRESS|APPLET) Such that it'll match any HTML tag that opens with the above specified...
5
by: nel | last post by:
I have two tags: <!--// Remove Begin //--and <!--// Remove End //--> I want to use regi_replace() to remove everything between these tags. The thing is, these tags can be repeated throughout...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.