removin html tags from string - but leaving a few behind

D

diablo

hi

i have seen several examples (blogs in particular)

http://www.lastkissed.com/?p=7#comments

where placing html into a textarea seems to be stripped out on the other
side. and yet retains some...

for example the above - i placed a </table> into the comment and submitted -
the <blockquote> came out as a block quote but the </table> seems to have
dissappeared.

is there a way i can do a similar box - ie so that if someone puts html into
it - it is stripped out?

thanks for help

Diablo
 
E

Evertjan.

diablo wrote on 01 jul 2005 in microsoft.public.inetserver.asp.general:
i have seen several examples (blogs in particular)

http://www.lastkissed.com/?p=7#comments

where placing html into a textarea seems to be stripped out on the
other side. and yet retains some...

for example the above - i placed a </table> into the comment and
submitted - the <blockquote> came out as a block quote but the
</table> seems to have dissappeared.

is there a way i can do a similar box - ie so that if someone puts
html into it - it is stripped out?

In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'');
%>
 
F

Foo Man Chew

How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?
 
E

Evertjan.

Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'');
%>

[please do not toppost on usenet]
How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?

I would think:

myString = myString.replace(/<img /ig,'%%%img ');
myString = myString.replace(/<a /ig,'%%%a ');
myString = myString.replace(/<\/a>/ig,'%%%/a>');


myString = myString.replace(/<[^>]*>/g,'');

myString = myString.replace(/%%%/g,'<');

NOT TESTED!

However this would not keep an end-of-line <a, <img.
Inline '%%%' strings need to be prevented.
But, as this is not a pais helpline, I leave that to your expertise.
 
F

Foo Man Chew

[please do not toppost on usenet]

Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.
 
E

Evertjan.

Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
[please do not toppost on usenet]

Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.

First I was not "telling" you, but asking you.
There is no need to insult someone informing you
to the content of netiquette.
Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.

===========

How are you getting on with the regex code lines?
 
D

diablo

How are you getting on with the regex code lines?


I found this

http://weblogs.asp.net/rosherove/archive/2003/05/13/6963.aspx#84206

but what i am wanting is the reverse of it - ie i want to say:

remove all html except for <blockquote> <em> <strong> <a>

whereas i think the above (link) removes the listed tags.

OK - i know that catering for all cases (ie missing end tags and spaces etc)
is difficult and long winded - but surely there is a simple way to do this.

Thanks again

Diablo
 
C

Chris Hohmann

diablo said:
I found this

http://weblogs.asp.net/rosherove/archive/2003/05/13/6963.aspx#84206

but what i am wanting is the reverse of it - ie i want to say:

remove all html except for <blockquote> <em> <strong> <a>

whereas i think the above (link) removes the listed tags.

OK - i know that catering for all cases (ie missing end tags and spaces
etc)
is difficult and long winded - but surely there is a simple way to do
this.

Use negative lookahead matching:

myString = myString.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
 
F

Foo Man Chew

Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.

I was merely demonstrating that in some cases either form is acceptable. I
know of no all-ruling governing body that states that one must use only one
form or the other. You like bottom-posting; good for you. That does not
mean that I have to change my posting habits to make you happy.
 
D

diablo

Use negative lookahead matching:

myString =

I am sorry - my reg ex is virtually nill

can you please provide a ASP scripty examlple

really appreciated

Diablo
 
E

Evertjan.

diablo wrote on 02 jul 2005 in microsoft.public.inetserver.asp.general:
I am sorry - my reg ex is virtually nill

can you please provide a ASP scripty examlple

<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript
 
P

PJones

ya, what is up with you and your non stop top posting comments.
Just keep it to yourself..



Evertjan. said:
Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
[please do not toppost on usenet]

Please don't tell me how to post, you come off sounding like a
self-appointed net nanny.

First I was not "telling" you, but asking you.
There is no need to insult someone informing you
to the content of netiquette.
Netiquette is not a joke,
but an important part of usenet for decades.

I am glad you followed my advice though.

===========

How are you getting on with the regex code lines?
 
E

Evertjan.

PJones wrote on 02 jul 2005 in microsoft.public.inetserver.asp.general:
ya, what is up with you and your non stop top posting comments.
Just keep it to yourself..

Certainly not.

The only way usenet remains such a usefull commodity is netiquette.

Correct posting belongs to netiquette, Mr Jones.
 
R

Roland Hall

:> Netiquette is not a joke,
: > but an important part of usenet for decades.
: >
: > I am glad you followed my advice though.
:
: I was merely demonstrating that in some cases either form is acceptable.

Laziness is only acceptable in Liberal environments. Show me any written
material that reads, scroll down, down, down, read down, scroll up, read
down, scroll up, read down, scroll up, read down.

I understand your philosophy, I just don't agree with it. "Help me with my
issue to make it easier for me but don't expect me to adhere to any standard
that makes it easier for you to help me. It's all about me."

Noted!

: I
: know of no all-ruling governing body that states that one must use only
one
: form or the other.

So, that's two noted things you don't know. Looks like a trend.

: You like bottom-posting; good for you. That does not
: mean that I have to change my posting habits to make you happy.

It's not bottom posting. It's related to a conversation. Yours is related
to nothing more than laziness. Either follow the standard and make it
easier for those helping you to make your life easier or soon you'll be
doing it on your own. Biting the hand that feeds you will cause you to
reach that goal sooner.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Roland Hall

: ya, what is up with you and your non stop top posting comments.
: Just keep it to yourself..

So, only you get to state your opinion? Let's review:

Evertjan made a pleasant request, which makes it easier for everyone and
still chose to satisfy the request.
Foo Man Chew asked for help and then whined and chose to ignore Evertjan's
request for help while catching an attitude.
You entered the conversation only to make a demand, offering no help
whatsoever.

Is it really too much to ask to follow a standard which makes the thread
easier to follow, especially when you're asking for help? Trim the text not
needed. It saves bandwidth and respond to the previous post as you would in
a conversation. Do you provide an answer before the question is asked? No,
that would be stupid.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
D

diablo

<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript


Any chance of a VBscript translation please - thanks - for all the help

Diablo
 
E

Evertjan.

diablo wrote on 03 jul 2005 in microsoft.public.inetserver.asp.general:
<%
function myReplace(s){
return
s.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
};
%>

using ASP Jscript


Any chance of a VBscript translation please - thanks - for all the help

These pages show both the replace syntax for Jscript and vbscript:

http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthreplace.asp

http://msdn.microsoft.com/library/en-us/script56/html/vsmthReplace.asp
 
B

Bob Lehmann

Roland Hall said:
: ya, what is up with you and your non stop top posting comments.
: Just keep it to yourself..

So, only you get to state your opinion? Let's review:

Evertjan made a pleasant request, which makes it easier for everyone and
still chose to satisfy the request.
Foo Man Chew asked for help and then whined and chose to ignore Evertjan's
request for help while catching an attitude.
You entered the conversation only to make a demand, offering no help
whatsoever.

Is it really too much to ask to follow a standard which makes the thread
easier to follow, especially when you're asking for help? Trim the text not
needed. It saves bandwidth and respond to the previous post as you would in
a conversation. Do you provide an answer before the question is asked? No,
that would be stupid.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp

Oops! I meant...
Do you provide an answer before the question is asked?
Alex Trebek does :>).

Bob Lehmann
 
R

Roland Hall

in message :
: Oops! I meant...
: >Do you provide an answer before the question is asked?
: Alex Trebek does :>).

Alex is on my list. (O;=

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top