УРОК 13 ИЗ 16
Регулярные выражения и работа с текстом
2 Теория
Регулярки в JavaScript
const text = "Пишите: ann@example.com или bob@mail.org";
console.log(text.match(/[\w.]+@[\w.]+\.\w+/g)); // все адреса
console.log(/^\d{4}-\d{2}-\d{2}$/.test("2026-10-29")); // true
console.log("a1b22c333".replace(/\d+/g, n => `[${n}]`)); // a[1]b[22]c[333]
const m = "29.10.2026".match(/(?<d>\d{2})\.(?<m>\d{2})\.(?<y>\d{4})/);
console.log(m.groups.y); // 2026
for (const x of text.matchAll(/\w+@\w+/g)) console.log(x[0]);
Флаги: g — все совпадения, i — без учёта регистра, m — многострочный режим, u — Unicode.
Методы строк
"JavaScript".slice(0, 4); // Java
"a-b-c".split("-"); // ["a","b","c"]
" hi ".trim();
"abc".padStart(5, "*"); // **abc
"ha".repeat(3); // hahaha
"Hello".includes("ell");
"x".localeCompare("y");
new Intl.NumberFormat("ru-RU", { style: "currency", currency: "UAH" }).format(1234.5);
new Date().toLocaleDateString("ru-RU", { day: "numeric", month: "long", year: "numeric" });