const regex = /(\d{2}\s*\d{2})\s*[\W*]\s*(\d{3,6})/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d{2}\\s*\\d{2})\\s*[\\W*]\\s*(\\d{3,6})', 'gm')
const str = `
серия 3204 09988, выдан 07.02.2005г, Отделом Внутренних Дел
серия 3204 № 099881 ,
32 04 № 099881 ОВД р-на 07.02.2005г.
серия 3204 № 099881 ,lorem
серия 3204 номер 099881, выдан 07.02.2005г, Отделом Внутренних Дел обл. код подразделения: 569-007
паспорт 32 04 099881
серия 32 03 818655, выдан
серия 32 11 045497, выдан 15.03.2011г.,
Серия 3214 № 426428 Выдан 03.03.2011 Отдел
Серия 32 10 № 980598 Выдан 03.07.2010 Отдел УФМС \\
32 08 803828 ОУФМС России по области
Паспорт 32 14 номер 498391
Паспорт серия 80 02 номер 279 781 по Оренбургской 31.04.2019
Паспорт 32 10 966241
`;
// 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