D
D
Daniil Igorevich2016-03-08 19:07:31
JavaScript
Daniil Igorevich, 2016-03-08 19:07:31

What is wrong with regular expression?

var re = /<!\-\-[^\-\->]*?\-\->/g;

var str = '..<!-- Мой -- комментарий \n тест -->';

alert( str.match(re) );

I want to get a comment through a regular expression, but the output is null. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2016-03-08
@Petr_Anisimov

Too smart.

var re = /<!--[\s\S]*?-->/g;
var str = '..<!-- Мой -- комментарий \n тест -->';
alert( str.match(re) );

A
Alexander Wolf, 2016-03-08
@mannaro

document.body.innerHTML.match(/<!--([\s\S]+?)-->/g)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question