const regex = new RegExp('[-+ ]?[178]?[ ]?\\d[ ]?\\d[ ]?\\d[ ]?\\d[ ]?\\d[ ]?\\d[ ]?', 'gm')
const str = `'Собственник. Продаётся НОВАЯ 5-х комнатная квартира только после ремонта, всё новое в идеальном состоянии. Оплата только наличными, можно валютой. Отдельное место на подземном паркинге, автономное отопление, Стены – наружные, крупноформатный рядовой поризиванный камень. Внутренние перегородки — камень двойной поризованный. 5B0HИTЬ 76 OO 26. Или на Baйбep +7931ll78О93'`;
// 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