Regexps and HTML comments

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

Add an "m" for multiline after the missing closing delimiter "/" for the regexp

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/11137

Jari Williamsson <jari.williamsson@mailbox.swipnet.se> wrote: I have troubles with the regexp to get HTML comments ("-->") 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

s=<<HERE
<!-- some
text -->
HERE

result = s.match(/\<!--(.*?)--\>/m)[1]
=> " some \ntext "

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/\.