const regex = /[Aa]/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[Aa]', 'gm')
const str = `Регулярные выражения представляют собой похожий, но гораздо более сильный инструмент
для поиска строк, проверки их на соответствие какому-либо шаблону и другой подобной
работы. Англоязычное название этого инструмента — Regular Expressions или просто RegExp.
Строго говоря, регулярные выражения — специальный язык для описания шаблонов строк.
АААА аааа АаАаАаАа 123 123 12345 11223344
А1Б2В3 АА11 ББ22ВВ 33ГГ44
Тест! Ещё! Даёшь! ЁЁЁёёё
QwertyЙцукен
+-,/[](), *** (***), a*(b+[c+d])*e/f+g-h
!!"""####\$\$\$\$\$%%%%%&&&'''(((())***++++,,,,,-----..//:::;;;;<<<<<===>>>????
@@@@@[[[[\\\\\\]]]]]^^^__\`\`\`\`\`{{{{|||||}}}}}~~~~~
<a href="#10">10: CamelCase -> under_score</a>;
<a href="#11">11: Удаление повторов</a>;
<a href="#12">12: Близкие слова</a>;
<a href="#13">13: Форматирование больших чисел</a>;
<a href="#14">14: Разделить текст на предложения</a>;
<a href="#15">15: Форматирование номера телефона</a>;
<a href="#16">16: Поиск e-mail'ов — 2</a>;`;
// 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