const regex = /[^\s,;.:-]*\$GNTXT[^\s,;.:-]*|[^\s,;.:-]*S\*12(?=\s)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[^\\s,;.:-]*\\$GNTXT[^\\s,;.:-]*|[^\\s,;.:-]*S\\*12(?=\\s)', 'gm')
const str = `?^ ×ô\\ ˜³^ <] Ï|] ci] Þí^ €K\` ÙsZ ÑûZ øÔZ ÑûZ -\\ æe^ Ÿ¯T dèZ €NT &ªP ÊY ¹–P èçO nßW ´X clQ ×ô\\ WöV V 4^ ˜³^ *\$U ÊY S|R KS }PY ,£R ŒÄN ÑûZ GX íaT ?ŽX >S käP ñÛX 4R îàQ …ÈX ’½P ¢O ¼‘W QýT ;T sY\\ —7U QýT ¼V "¬U Î T VwY ;T "¬U óZV hæU ÃT ›±Y ¾U ÙvN >S ¦«J ,¦F CL bðG jhG ¦ÇµbH ibat3 uA ¸ ô~ ô~ oð\$GNTXT,01,01,00,txbuf alloc S*12
haumaukhaS*12
oð\$GNTXT
\$GNTXT, and that ends with S*12.`;
// 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