const regex = /^(\w{2})\s*(\w{5})\s*(\w{13})\s*(\d{3})\s*(\d{7})\s*(.*?)\s*(\d{6})$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\w{2})\\s*(\\w{5})\\s*(\\w{13})\\s*(\\d{3})\\s*(\\d{7})\\s*(.*?)\\s*(\\d{6})$', 'gm')
const str = `VA0017487146000066460126132202STRONG 4P 4X44G000099
VA 00174 8714600006646 012 6132202 STRONG 4P 4X44G 000099
VA001748714600006640126132202STRONG 4P 4X44G000099
VA 00174 871460000664 012 6132202 STRONG 4P 4X44G 000099`;
// 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