regexp strip html

Discussion in 'Ruby' started by Une bévue, Mar 26, 2006.

  1. Une bévue

    Une bévue Guest

    i have a regexp able to strip html :

    /<[^>]*>/

    however, between <script and </script> all the "text is preserved, tjen
    i've tried :

    def stripHTML
    # self.gsub(/<\S[^><]*>/, '')
    self.gsub(/\A.*<body [^>]*>(.*)<\/body>\s*\Z/, '\1').gsub(/<[^>]*>/,
    '')
    end

    without success : the various javascript functions are kept ?

    what's my error here ?

    --
    une bévue
     
    Une bévue, Mar 26, 2006
    #1
    1. Advertising

  2. Une bévue

    Paul Battley Guest

    T24gMjYvMDMvMDYsIFVuZSBiw6l2dWUgPHBlcmUubm9lbEBsYXBvbmllLmNvbS5pbnZhbGlkPiB3
    cm90ZToKPiBpIGhhdmUgYSByZWdleHAgYWJsZSB0byBzdHJpcCBodG1sIDoKPgo+IC88W14+XSo+
    Lwo+Cj4gaG93ZXZlciwgYmV0d2VlbiA8c2NyaXB0IGFuZCA8L3NjcmlwdD4gYWxsIHRoZSAidGV4
    dCBpcyBwcmVzZXJ2ZWQsIHRqZW4KLi4uCj4gd2hhdCdzIG15IGVycm9yIGhlcmUgPwoKTG9vayBh
    dCBpdCB0aGlzIHdheTogeW91IGhhdmUgJzxzY3JpcHQ+SmF2YXNjcmlwdDwvc2NyaXB0PicuIFlv
    dQpyZW1vdmUgZXZlcnl0aGluZyBiZXR3ZWVuIGFuZ2xlIGJyYWNrZXRzLiBZb3Ugc3RpbGwgaGF2
    ZSAnSmF2YXNjcmlwdCcsCmJlY2F1c2UgdGhhdCdzIG5vdCBhY3R1YWxseSBpbnNpZGUgPC4uLj4u
    CgpUaGUgc2ltcGxlc3Qgc29sdXRpb24gaXMgcHJvYmFibHkgdG8gZG8gc29tZXRoaW5nIGxpa2Ug
    dGhpcyBiZWZvcmUKc3RyaXBwaW5nIG91dCB0aGUgcmVtYWluaW5nIHRhZ3M6Cgpnc3ViKC88c2Ny
    aXB0Lio/PC9zY3JpcHQ+L2ltLCAnJykKClBhdWwuCg==
     
    Paul Battley, Mar 27, 2006
    #2
    1. Advertising

  3. Une bévue

    Une bévue Guest

    Paul Battley <> wrote:

    > The simplest solution is probably to do something like this
    > before

    stripping out the remaining tags:

    gsub(/<script.*?</script>/im,
    > '')


    yes, sounds clever ))

    --
    une bévue
     
    Une bévue, Mar 27, 2006
    #3
    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. Michal A. Valasek

    How to strip HTML markup from string?

    Michal A. Valasek, Aug 9, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,307
    Yan-Hong Huang[MSFT]
    Aug 12, 2003
  2. Jon Maz
    Replies:
    4
    Views:
    1,070
    Jon Maz
    Jun 15, 2004
  3. Aquila
    Replies:
    35
    Views:
    504
    Mathieu Bouchard
    Mar 31, 2005
  4. Joao Silva
    Replies:
    16
    Views:
    403
    7stud --
    Aug 21, 2009
  5. yelipolok
    Replies:
    4
    Views:
    290
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page