• ARعربي
  • ENEnglish
  • ESEspañol
  • FAفارسی
  • FRFrançais
  • IDIndonesia
  • ITItaliano
  • JA日本語
  • KO한국어
  • RUРусский
  • TRTürkçe
  • UKУкраїнська
  • ZH简体中文

ما قصد داریم این پروژهٔ متن‌باز را در دسترس همهٔ مردم در سرتاسر دنیا قرار دهیم.

به ترجمهٔ محتوای این آموزش به زبان خودتان کمک کنید/a>.

    نقشه آموزش
    اشتراک گذاری
    • آموزش
    • عبارات باقاعده (Regular Expression)
    • Greedy and lazy quantifiers
    بازگشت به درس
    این محتوا تنها در این زبان‌ها موجود است: English, Español, Français, Italiano, 日本語, Русский, Українська, 简体中文. لطفاً به ما

    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 -->', '<!---->'
    • © 2007—2025  Ilya Kantor
    • دربارهٔ پروژه
    • تماس با ما