Find all HTML comments in the text:
str = '.. <!-- My -- comment \n test --> .. <!----> .. ' re = /.. your regexp ../ str.match(re) // '<!-- My -- comment \n test -->', '<!---->'
Решение
Решение
We need to match everything .* from comment start <!-- to comment end -->. To let the comment end match, the quantifier should be lazy.
So, the first-glance solution for a task is <!--.*?-->.
But we remember that JavaScript dot doesn’t match a newline. So let’s replace it by a more generic [\s\S].
Finally:
str = '.. <!-- Welcome -- comment \n test --> .. <!----> .. ' re = /<!--[\s\S]*?-->/g alert( str.match(re) )
#289