473,856 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5145
I ~guess~ this non-regular expression may work:
sPost = Request.Form("T heTextArea")
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.c om> wrote in message
news:OK******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP11.phx.gbl...
I ~guess~ this non-regular expression may work:
sPost = Request.Form("T heTextArea")
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.c om> wrote in message
news:OK******** ******@TK2MSFTN GP12.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.publi c.inetserver.as p.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,"##&##").repl ace(/<[^>]
+>/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
12248
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 them. What I want to do is filter out a subset of this dict to produce another dict that satisfies a set of criteria (in this case whether it contains all four values) to end up with something
1
7856
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 from queries. Let me just add that Allen Browne excellent article about this subject may not apply to this scenario on an elementary level. (Here's the link to the article; Filter a Form on a Field in a Subform -...
3
6618
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 the text value is on a different table. The me.filter is then a text instead of the id-number from the lookup table. This causes the report to prompt for the parameter. How do I get by this problem? Do I need to create a temporary table? I rather...
8
6541
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 there are many examples. BUT, they fail sometimes. The techique is to pass the form's Me.filter as the "where condition" in a Docmd.openreport statement in code behind a "print button" on the form.
3
11980
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 subform..... This MSDN article however makes it sound as simple as clicking "Filter by Form", entering the search criterial in the form and/or it's subforms, then just clicking "Apply Filter"...... ...
3
2486
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 set buffer=false on a large page). Now the problem: If I turn on buffering on a large page, the page output (to the browser) is correct a few times (sometines just once, sometime 2-3 times...on the same page) then I seem to either lose data...
4
1813
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 this code reusable to all my applications, and by making this as a HttpModule I can implement this feature on existing .Net applications by editing the we.config and nothing else... My problem is that that I can't get this to work.
9
15066
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" How can I display both htm & html files at the same time? Thanks
5
2662
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 this... Exmaple web site: http://allenbrowne.com/ser-62.html My Code: 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few criteria as they wish, _ and results...
1
4177
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 allows me to filter based on variables in a single table. I would like to have a search form where I can select multiple variables (from various linked tables) to filter by, and return results based on this multi-table filter. Allen Browne...
0
9758
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11049
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10692
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10772
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10378
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7928
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7086
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.