Regexps and HTML comments

J

Jari Williamsson

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
 
G

Greg Willits

Jari said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top