const regex = /(?i)(\d+\$)(a*(\W))from(a*(\W))steam(?:\s*\n)*\s?\[(steamcommunity\.com\/gift\/[^\]]+)\]\((https?:\/\/[^\s]+\.[^\s]+)\)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?i)(\\d+\\$)(a*(\\W))from(a*(\\W))steam(?:\\s*\\n)*\\s?\\[(steamcommunity\\.com\\\/gift\\\/[^\\]]+)\\]\\((https?:\\\/\\\/[^\\s]+\\.[^\\s]+)\\)', 'gm')
const str = `50\$ From steam
[steamcommunity.com/gift/8349393928202](https://scamlink.net/etc)
200\$ from steam
[steamcommunity.com/gift/8349393928202](http://another.link)
Random message 50\$ From steam
[steamcommunity.com/gift/8349393928202](https://scamlink.net/etc) @everyone`;
// 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