const regex = /(^.*?((?:[A-Za-z]+_)+[A-Z]\w+)(?:-([0-9]{8}-[0-9]{6})-([0-9]{8}-[0-9]{6}))?)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(^.*?((?:[A-Za-z]+_)+[A-Z]\\w+)(?:-([0-9]{8}-[0-9]{6})-([0-9]{8}-[0-9]{6}))?)', 'gm')
const str = `mixexecutor:check_atom_exists:740 - requested to check this machine : ET_colBackDDW_Temp
output_of_reports/PII/36478_ABP_BAL_liquidpressure-20210831-123456-20210831-172355.bat.yz
packofexecutors:_to_signle_que:869-no mata for file'/private/external_control_time_mapped_low_volume/IBA/54378_BD-RT_69-1-1-20200831-152355-20200831-172355.dat.xz'
packofexecutors:_to_signle_que:869-no mata for file'/private/external_control_time_mapped_low_volume/IBA/54378_BD-RT_69-1-20200831-152355-20200831-172355.dat.xz'
mixexecutor:check_atom_exists:740 - requested to check this machine : Eanes_colBack12_current
packofexecutors._check_tar.587-nr of missed files=78 nr of skipped records=6547 nr of records not exist=0
packofexecutors._filter_mistacl_signals:777 - invalid atomname for RT_6:ESmotormeaninfAmkl`;
// 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