const regex = /(24180|27268|3696|17532)(?!.*\1)\s+\d+\s+\w+\s+\K\w+/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(24180|27268|3696|17532)(?!.*\\1)\\s+\\d+\\s+\\w+\\s+\\K\\w+', 'gms')
const str = `2024-04-14 04:56:56.714-0300 24180 20660 UI at64_1 [Ready] W: Retrying to obtain clipboard.
2024-04-14 04:56:56.714-0300 27268 31992 UI at64_4 [Ready] W: Retrying to obtain clipboard.
2024-04-14 04:56:56.714-0300 3696 20128 UI at64_3 [Ready] W: Retrying to obtain clipboard.
2024-04-14 04:56:56.765-0300 3696 20128 UI at64_3 [Ready] W: Retrying to obtain clipboard.
2024-04-14 04:56:56.765-0300 27268 31992 UI at64_4 [Ready] W: Retrying to obtain clipboard.
2024-04-14 04:56:56.765-0300 17532 1384 UI at64_2 [Ready] W: Retrying to obtain clipboard.
`;
// 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