$re = '/(?<!cpc|accounts\.)(google|bing|search\.yahoo|search\.myway|yandex|duckduckgo|ecosia|search\.tb\.ask|baidu)(?!.*cpc)/m';
$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';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php