import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<!cpc|accounts\\.)(google|bing|search\\.yahoo|search\\.myway|yandex|duckduckgo|ecosia|search\\.tb\\.ask|baidu)(?!.*cpc)";
final String string = "google/cpc/[google][cpc][house][sale]\n"
+ "google/cpc/[google][cpc][condo][sale]\n"
+ "accounts.google.com.sg\n"
+ "accounts.google.co.id\n"
+ "google.com\n"
+ "google.com.ph\n"
+ "google.co.th\n"
+ "bing.com\n"
+ "google.co.uk\n"
+ "com.google.android.googlequicksearchbox\n"
+ "google.com.sg\n"
+ "google.com.au\n"
+ "google.com.vn\n"
+ "google.ca\n"
+ "google.co.id\n"
+ "google.com.hk\n"
+ "search.yahoo.com\n"
+ "duckduckgo.com\n"
+ "google.de\n"
+ "ph.search.yahoo.com\n"
+ "google.co.in\n"
+ "google.fr\n"
+ "google.co.jp\n"
+ "google.co.kr\n"
+ "google.com.my\n"
+ "google.ae\n"
+ "google.se\n"
+ "google.ch\n"
+ "int.search.myway.com\n"
+ "yandex.ru\n"
+ "google.ru\n"
+ "google.com.tw\n"
+ "google.nl\n"
+ "cn.bing.com\n"
+ "ecosia.org\n"
+ "google.it\n"
+ "google.dk\n"
+ "google.co.nz\n"
+ "int.search.tb.ask.com\n"
+ "search.yahoo.co.jp\n"
+ "google.co.za\n"
+ "google.no\n"
+ "google.es\n"
+ "google.be\n"
+ "th.search.yahoo.com\n"
+ "google.fi\n"
+ "baidu.com\n"
+ "google.ie\n"
+ "google.com.tr\n"
+ "uk.search.yahoo.com";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html