const regex = /\d{1}\s{16}(\d{4})(\d{9})\s{7}[A-Z\s]{25}(\d{10})[A-Za-z\s]{32}\s{3}\d{1}\d{2}[A-Za-z\s\d]{10}(\d{6})(\d{13})\d{3}\s{5}\d{2}[A-Z]{1}(\d{6})\d{2}\s{2}\d{13}\s{45}\d{2}(\d{14})([A-Z\s]{35})\s{5}([A-Z0-9\s]{40})\s{7}/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\d{1}\\s{16}(\\d{4})(\\d{9})\\s{7}[A-Z\\s]{25}(\\d{10})[A-Za-z\\s]{32}\\s{3}\\d{1}\\d{2}[A-Za-z\\s\\d]{10}(\\d{6})(\\d{13})\\d{3}\\s{5}\\d{2}[A-Z]{1}(\\d{6})\\d{2}\\s{2}\\d{13}\\s{45}\\d{2}(\\d{14})([A-Z\\s]{35})\\s{5}([A-Z0-9\\s]{40})\\s{7}', 'g')
const str = `1 0839854268058 0002611724 101312366 0712170000000020887041 08A24111718 1000000000100 0100001065768010JULIO CEZAR OZORIO DA SILVA BL S AP 202 0200194800000ALVORADA RS 000002`;
// 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