473,394 Members | 1,645 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,394 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 5128
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 variable length list of associated values after...
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 not less experience with filtering data outside...
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 problem until I want to filter a combo box where...
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 the filter." I have searched the newsgroups, and...
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 which are either on subforms or span more than one...
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 buffer...or....if I have a large unbuffered stream (i.e. I...
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, or some other fancy feature... I want to make...
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 files (*.html)|*.html|Htm files (*.htm)|*.htm" ...
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 working. Would someone be kind enough to take a look at...
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 the whole database. The search form I have now only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.