const regex = /(?si)m_dwErrorCode\s*=\s*(?<code>\dx\d+);\s*_stprintf\(.*?\(.*?\((?<description>.*?)\).*?;\s*m_dwOutError\s*=\s*(?<error>[\w_]+);\s*m_OutSeverity\s*=\s*(?<severity>[\w_]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?si)m_dwErrorCode\\s*=\\s*(?<code>\\dx\\d+);\\s*_stprintf\\(.*?\\(.*?\\((?<description>.*?)\\).*?;\\s*m_dwOutError\\s*=\\s*(?<error>[\\w_]+);\\s*m_OutSeverity\\s*=\\s*(?<severity>[\\w_]+)', 'gm')
const str = `m_dwErrorCode = 0;
m_dwOutError = HOP_OK;
m_OutSeverity = CCC_INFORMATION;
_stprintf(m_OutDevStr, _T(""));
if (0x00000000 & value)
{
m_dwErrorCode = 0x0;
/* Ready state. */
// m_StatusStr = " Ready(eSTATUS_READY)";
}
if (0x00000001 & value)
{
m_bProceeding = true;
/* proceed */
//m_StatusStr = " Proceeding(eSTATUS)";
}
if (0x00002000 & value)
{
m_bEmpty = true;
// We only want to check this error only at certain times.
if (m_bCheckEmpty)
{
if ((m_Attributes.dwMediaID == CUBE1) ||
(m_Attributes.dwMediaID == CUBE2) ||
/*(m_Attributes.dwMediaID == SCALLOPED) ||*/ // Added
(m_Attributes.dwMediaID == FOLDED))
{
m_dwErrorCode = 0x00002000;
_stprintf(m_OutDevStr, _T("0x1000 - %s(MP Tray Empty)"), errorStr);
m_dwOutError = HOP_TRAY_EMPTY;
m_OutSeverity = CCC_INFORMATION;
}
}
//HOP_TRAY_EMPTY
///* MSI empty. */
//m_bTrayEmpty = true;
//// m_StatusStr = " MSI empty(eSTATUS_MSI_EMPTY)";
}
if (0x00004000 & value)
{
/* empty. */
m_dwErrorCode = 0x4000;
_stprintf(m_OutDevStr, _T("0x4000 - %s(Tray 1 empty)"), errorStr);
m_dwOutError = HOP_TRAY_01_EMPTY;
m_OutSeverity = CCC_INFORMATION;
}
if (0x00008000 & value)
{
/* Tray 2 empty. */
m_dwErrorCode = 0x8000;
_stprintf(m_OutDevStr, _T("0x8000 - %s(Tray 2 empty)"), errorStr);
m_dwOutError = HOP_TRAY_02_EMPTY;
m_OutSeverity = CCC_INFORMATION;
}
if (0x00010000 & value)
{
/* Tray 3 empty. */
m_dwErrorCode = 0x10000;
_stprintf(m_OutDevStr, _T("0x10000 - %s(Tray 3 empty)"), errorStr);
m_dwOutError = HOP_TRAY_03_EMPTY;
m_OutSeverity = CCC_INFORMATION;
}`;
// 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