472,353 Members | 1,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

filter html-tags, but not all...

Hello

I was wondering if you guys could help me. im building a small messageboard
and i want to filter all html-tags except these ones:

<b> <i> <img.........> <font....>

how to build such a reg exp pattern?

TIA
/Lasse
Jul 19 '05 #1
4 5078
I ~guess~ this non-regular expression may work:
sPost = Request.Form("TheTextArea")
sPost = Replace(sPost, "<", "&lt;")
sPost = Replace(sPost, "&lt;b>", "<b>")
sPost = Replace(sPost, "&lt;/b>", "</b>")
sPost = Replace(sPost, "&lt;i>", "<i>")
sPost = Replace(sPost, "&lt;/i>", "</i>")
sPost = Replace(sPost, "&lt;img", "<img")
sPost = Replace(sPost, "&lt;font", "<font")
sPost = Replace(sPost, "&lt;/font>", "</font>")
If I got that right, it'll replace all the <'s with &lt;'s, and then go back
and re-replace the <b, <i, <img, <font and they're closing equivalents.
This will still leave > everywhere, but that shouldn't matter. I'm sure
there is a more robust solution out there, anyway.

Ray at work

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Hello

I was wondering if you guys could help me. im building a small messageboard and i want to filter all html-tags except these ones:

<b> <i> <img.........> <font....>

how to build such a reg exp pattern?

TIA
/Lasse

Jul 19 '05 #2
hmm, i was hoping for a reg.exp solution

/Lasse
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:uz**************@TK2MSFTNGP11.phx.gbl...
I ~guess~ this non-regular expression may work:
sPost = Request.Form("TheTextArea")
sPost = Replace(sPost, "<", "&lt;")
sPost = Replace(sPost, "&lt;b>", "<b>")
sPost = Replace(sPost, "&lt;/b>", "</b>")
sPost = Replace(sPost, "&lt;i>", "<i>")
sPost = Replace(sPost, "&lt;/i>", "</i>")
sPost = Replace(sPost, "&lt;img", "<img")
sPost = Replace(sPost, "&lt;font", "<font")
sPost = Replace(sPost, "&lt;/font>", "</font>")
If I got that right, it'll replace all the <'s with &lt;'s, and then go back and re-replace the <b, <i, <img, <font and they're closing equivalents.
This will still leave > everywhere, but that shouldn't matter. I'm sure
there is a more robust solution out there, anyway.

Ray at work

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Hello

I was wondering if you guys could help me. im building a small

messageboard
and i want to filter all html-tags except these ones:

<b> <i> <img.........> <font....>

how to build such a reg exp pattern?

TIA
/Lasse


Jul 19 '05 #3
Lasse Edsvik wrote:
hmm, i was hoping for a reg.exp solution

Patience. Chris (Hohmann) usually doesn't start posting this early in the
day. ;-)

If you're really impatient, you may want to Google this group for some of
Chris' RegExp posts that may help you figure it out for yourself...

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #4
Lasse Edsvik wrote on 27 okt 2003 in
microsoft.public.inetserver.asp.general:
I was wondering if you guys could help me. im building a small
messageboard and i want to filter all html-tags except these ones:

<b> <i> <img.........> <font....>

how to build such a reg exp pattern?


This answer is in [serverside-asp ;-)] Jscript
and supposes you also want to keep </b>, </i>, etc.
// replace the < of those 8 with ##&##
t = t.replace(/<{1}?(?=\/?(b|i|img|font)( |>))/g,"##&##")

// replace all other tags with a space
t = t.replace(/<[^>]+>/g," ")

// replace all ##&## back to <
t = t.replace(/##&##/g,"<")

=========================

// all in one single line:
t = t.replace(/<{1}?(?=\/?(b|i|img|font)( |>))/g,"##&##").replace(/<[^>]
+>/g," ").replace(/##&##/g,"<")

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #5

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

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have...
3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying...
3
by: dhowell | last post by:
In reading some of the posts on this group, it appears as though it is not strait forward at all to filter a form, which has subforms, by criteria...
3
by: Brad | last post by:
I have a response filter which injects "standard" html into my pages. The filter works fine when the initial stream is small enough not to...
4
by: Thomas | last post by:
I want to be able to implement a filter that manipulates the output from the server... Maybe replacing some words, or highlighting a search string,...
9
by: John | last post by:
Hi I am using the following for the filter but it allows me to display only one of either an htm or an html file. dlgOpenFile.Filter = "Html...
5
by: Ron S | last post by:
After days of searching I finally an example that would work with my application, the only problem is after entering all of the code it is not...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.