removin html tags from string - but leaving a few behind

Discussion in 'ASP General' started by diablo, Jul 1, 2005.

  1. diablo

    diablo Guest

    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
     
    diablo, Jul 1, 2005
    #1
    1. Advertising

  2. diablo

    Evertjan. Guest

    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,'');
    %>

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 1, 2005
    #2
    1. Advertising

  3. diablo

    Foo Man Chew Guest

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



    > In ASP Jscript:
    >
    > <%
    > myString = myString.replace(/<[^>]*>/g,'');
    > %>
     
    Foo Man Chew, Jul 1, 2005
    #3
  4. diablo

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 1, 2005
    #4
  5. diablo

    Foo Man Chew Guest

    > [please do not toppost on usenet]

    Please don't tell me how to post, you come off sounding like a
    self-appointed net nanny.
     
    Foo Man Chew, Jul 1, 2005
    #5
  6. diablo

    Evertjan. Guest

    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?

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 1, 2005
    #6
  7. diablo

    diablo Guest


    > 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
     
    diablo, Jul 2, 2005
    #7
  8. "diablo" <> wrote in message
    news:Xekxe.1044$...
    >
    >
    >> 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.


    Use negative lookahead matching:

    myString = myString.replace(/<(?!\/?(blockquote|em|strong|a))[^>]*>/gi,"");
     
    Chris Hohmann, Jul 2, 2005
    #8
  9. diablo

    Foo Man Chew Guest

    > 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.
     
    Foo Man Chew, Jul 2, 2005
    #9
  10. diablo

    diablo Guest


    > Use negative lookahead matching:
    >
    > myString =

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


    I am sorry - my reg ex is virtually nill

    can you please provide a ASP scripty examlple

    really appreciated

    Diablo
     
    diablo, Jul 2, 2005
    #10
  11. diablo

    Evertjan. Guest

    diablo wrote on 02 jul 2005 in microsoft.public.inetserver.asp.general:
    >> Use negative lookahead matching:
    >>
    >> myString =

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

    >
    > 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


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 2, 2005
    #11
  12. diablo

    PJones Guest

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



    "Evertjan." <> wrote in message
    news:Xns9687182484BBeejj99@194.109.133.242...
    > 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?
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
     
    PJones, Jul 2, 2005
    #12
  13. diablo

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 2, 2005
    #13
  14. diablo

    Roland Hall Guest

    "Foo Man Chew" <> wrote in message
    news:%...
    :> 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
     
    Roland Hall, Jul 3, 2005
    #14
  15. diablo

    Roland Hall Guest

    "PJones" <> wrote in message
    news:...
    : 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
     
    Roland Hall, Jul 3, 2005
    #15
  16. diablo

    diablo Guest


    > <%
    > 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
     
    diablo, Jul 3, 2005
    #16
  17. diablo

    Evertjan. Guest

    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


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jul 3, 2005
    #17
  18. diablo

    Bob Lehmann Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "PJones" <> wrote in message
    > news:...
    > : 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
     
    Bob Lehmann, Jul 3, 2005
    #18
  19. diablo

    Roland Hall Guest

    "Bob Lehmann" wrote in message news:...
    :
    : 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
     
    Roland Hall, Jul 4, 2005
    #19
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kurt

    Removin a user control

    Kurt, Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    358
    Karl Seguin
    Jul 2, 2003
  2. Falcolas

    os.fork leaving processes behind

    Falcolas, Dec 28, 2007, in forum: Python
    Replies:
    2
    Views:
    415
    Falcolas
    Dec 31, 2007
  3. Kevin Blount
    Replies:
    2
    Views:
    135
    Kevin Blount
    Dec 6, 2005
  4. Rob Hunter
    Replies:
    4
    Views:
    121
    Rob Hunter
    Jul 11, 2007
  5. sroemerm

    removin \n from only part of a string

    sroemerm, Oct 27, 2004, in forum: Perl Misc
    Replies:
    10
    Views:
    173
    sroemerm
    Oct 29, 2004
Loading...

Share This Page