نريد أن نتيح هذا المشروع المفتوح المصدر إلى كل الناس حول العالم. من فضلك ساعدنا على ترجمة محتوى هذه السلسله للغة التى تعرفها.
الرجوع الي الدرس
هذة المادة العلميه متاحه فقط باللغات الأتيه: English, Español, Français, Italiano, 日本語, Русский, Українська, Oʻzbek, 简体中文. من فضلك, ساعدنا قم بالترجمه إلى عربي.

Find HTML comments

Find all HTML comments in the text:

let regexp = /your regexp/g;

let str = `... <!-- My -- comment
 test --> ..  <!----> ..
`;

alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'

We need to find the beginning of the comment <!--, then everything till the end of -->.

An acceptable variant is <!--.*?--> – the lazy quantifier makes the dot stop right before -->. We also need to add flag s for the dot to include newlines.

Otherwise multiline comments won’t be found:

let regexp = /<!--.*?-->/gs;

let str = `... <!-- My -- comment
 test --> ..  <!----> ..
`;

alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
Morty Proxy This is a proxified and sanitized view of the page, visit original site.