const regex = /(new=\"\w+\").*(info=\"\w+\")/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(new=\\"\\w+\\").*(info=\\"\\w+\\")', 'gm')
const str = `<hello script="2.5">
<welcome>
<hgsdhjaghjdghjagdjhgjdhgdajhgdajhgdhjjgfkjg
<number new="0x0000-0x3FF" Id="bhi" Range="4" no_id="hello" />
< ----jsdjhsdjndkjjdhjdJHksdkjdnknnddnekfgrejgjorgj jregjgkrjglrjgojggjorjg -- >
< number new="0x02" Id="bhi" Unit="0" Range="4" info="0x00000012" no_id="hi all" />
< number new="0x04" Id="bhi" Unit="0" Range="4" info="0x0000023f" no_id="dbhwd" />
< ---- dfiuhdwiudi iwqdidffenfj odwqjdjqwgru jdqkkjwfkjfwn odHHOIJD JSDNKS nsk---- >
< number new="0x06" Id="bhi" Unit="0" Range="4" info="0x00000f22" no_id="sjkdnkl jdsnj" />
< number new="0x08" Id="bhi" Unit="0" Range="4" info="0x00000f1b" no_id="dm o" />
< -- bdheuh jwdhjwdkiwh ---- >
< number new="0x32" Id="bhi" Range="4" info="0x000012f5" no_id="he d kd" />
< number new="0x336" Id="bhi" Range="4" info="0x00000df2" no_id="dnkwn" />
< number new="0x428" Id="bhi" Range="4" info="0x0001cbf2" no_id="h nd" />
< -- new model vdhjsb ---- >
< number new="0x06" Id="bhi" Unit="0" unit_id="hi_all" Range="2" info="0x0f22" no_id="sjkdnkl jdsnj' />
< number new="0x08" Id="bhi" Unit="0" unit_id="this new" Range="4" info="0x00000f1b" no_id="dm o" /
< --- adhhj jdwjdkkj jsSDjkasdj jefnflefk kjsjfoekfle kajfofkp ksaokdfpef ---- >
< -- the end of file---- >`;
// 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