Regexps and HTML comments

Discussion in 'Ruby' started by Jari Williamsson, Nov 22, 2007.

  1. I have troubles with the regexp to get HTML comments ("<!-- some text
    -->") from a long (multi-line) string. Comments that have line breaks
    aren't found, only the comments that are on the same line.

    Here's my current code:
    result = s.match(/\<!--(.*?)--\>)

    How do I get the regexp to scan for the pattern beyond newlines?


    Best regards,

    Jari Willimasson
    Jari Williamsson, Nov 22, 2007
    #1
    1. Advertising

  2. Jari Williamsson

    Greg Willits Guest

    Jari Williamsson wrote:
    > I have troubles with the regexp to get HTML comments ("<!-- some text
    > -->") from a long (multi-line) string. Comments that have line breaks
    > aren't found, only the comments that are on the same line.
    >
    > Here's my current code:
    > result = s.match(/\<!--(.*?)--\>)
    >
    > How do I get the regexp to scan for the pattern beyond newlines?



    Try this one:
    result = s.match(/\<!--([\s\S]*?)--\>/)

    -- gw

    --
    Posted via http://www.ruby-forum.com/.
    Greg Willits, Nov 22, 2007
    #2
    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. Replies:
    0
    Views:
    1,104
  2. Paddy

    Regexps and lists

    Paddy, Feb 11, 2007, in forum: Python
    Replies:
    1
    Views:
    289
    John Machin
    Feb 11, 2007
  3. Monk
    Replies:
    10
    Views:
    1,448
    Michael Wojcik
    Apr 20, 2005
  4. Brendan Byrd/SineSwiper

    Removing Perl comments and strings using regexps

    Brendan Byrd/SineSwiper, Jul 17, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    148
    Brendan Byrd/SineSwiper
    Jul 18, 2003
  5. Replies:
    4
    Views:
    589
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page