const regex = /(?<!cpc|accounts\.)(google|bing|search\.yahoo|search\.myway|yandex|duckduckgo|ecosia|search\.tb\.ask|baidu)(?!.*cpc)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<!cpc|accounts\\.)(google|bing|search\\.yahoo|search\\.myway|yandex|duckduckgo|ecosia|search\\.tb\\.ask|baidu)(?!.*cpc)', 'gm')
const str = `google/cpc/[google][cpc][house][sale]
google/cpc/[google][cpc][condo][sale]
accounts.google.com.sg
accounts.google.co.id
google.com
google.com.ph
google.co.th
bing.com
google.co.uk
com.google.android.googlequicksearchbox
google.com.sg
google.com.au
google.com.vn
google.ca
google.co.id
google.com.hk
search.yahoo.com
duckduckgo.com
google.de
ph.search.yahoo.com
google.co.in
google.fr
google.co.jp
google.co.kr
google.com.my
google.ae
google.se
google.ch
int.search.myway.com
yandex.ru
google.ru
google.com.tw
google.nl
cn.bing.com
ecosia.org
google.it
google.dk
google.co.nz
int.search.tb.ask.com
search.yahoo.co.jp
google.co.za
google.no
google.es
google.be
th.search.yahoo.com
google.fi
baidu.com
google.ie
google.com.tr
uk.search.yahoo.com`;
// 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