# Regexps and HTML comments

**URL:** <https://www.ruby-forum.com/t/regexps-and-html-comments/121020>\
**Category:** Ruby\
**Created:** [November 22, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/regexps-and-html-comments/121020 "2007-11-22T20:26:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jari\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jari\_W](https://www.ruby-forum.com/u/Jari_W)\
**Post date:** [November 22, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/regexps-and-html-comments/121020/1 "2007-11-22T20:26:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jari\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jari\_W](https://www.ruby-forum.com/u/Jari_W)\
**Post date:** [November 22, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/regexps-and-html-comments/121020/2 "2007-11-22T20:38:04Z")

</div>

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](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/11137)

Jari W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Jari\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jari\_W](https://www.ruby-forum.com/u/Jari_W)\
**Post date:** [November 22, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/regexps-and-html-comments/121020/3 "2007-11-22T20:39:41Z")

</div>

Jari W. 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?

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

– gw

---

<div class="post-metadata">

**Author:** ![Jari\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@Jari\_W](https://www.ruby-forum.com/u/Jari_W)\
**Post date:** [November 22, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/regexps-and-html-comments/121020/4 "2007-11-22T20:39:50Z")

</div>

s=\<\<HERE

HERE

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