const regex = /{% comment %}.*{% endcomment %}/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('{% comment %}.*{% endcomment %}', 'gms')
const str = `--font-heading: {{ settings.header_font_1_1.family }};
--font-standard: {{ settings.general_font_1_1.family }};
--body-font-size: {{settings.body_font_size}}px;
--font-small: 14px;
--font-medium: 17px;
--font-bold: 300;
--size-h1: {{settings.heading_size_1}}px;
--size-h2: {{settings.heading_size_2}}px;
--size-h3: {{settings.heading_size_3}}px;
--size-h4: {{settings.heading_size_4}}px;
--size-h5: {{settings.heading_size_5}}px;
--size-h6: {{settings.heading_size_6}}px;
--top-font-size: {{settings.top_bar_size}}px;
--product-font-size: {{settings.product_title_size}}px;
--product-price-size: {{settings.product_price_size}}px;
--footer-size: {{ settings.footer_font_size }}px;
{% comment %} --home-title-font-size: {{settings.home_title_size}}px; {% endcomment %}
--product-detail-title-size: {{settings.product_detail_title_size}}px;
--font-icon : 20px;
--font-small-icon: 21px;
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions