import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "/pt-br/aeroportos/(?!brasil)|/pt-br/localidades/(?!brasil)|/pt-br/locadora/[^/]+/((?!brasil).)+$";
final String string = "/pt-br/aeroportos/estados-unidos/mco-orlando-florida\n"
+ "/pt-br/\n"
+ "/pt-br/alugar/estados-unidos/miami-florida\n"
+ "/pt-br/aeroportos/estados-unidos/fll-fort-lauderdale-hollywood-fort-lauderdale-florida\n"
+ "/pt-br/localidades/estados-unidos/miami-florida\n"
+ "/pt-br/carros/estados-unidos/miami-florida\n"
+ "/pt-br/localidades/brasil/rio-de-janeiro-rio-de-janeiro\n"
+ "/pt-br/localidades/brasil/sao-paulo-sao-paulo\n"
+ "/pt-br/aeroportos/brasil/fln-hercilio-luz-florianopolis-santa-catarina\n"
+ "/pt-br/locadora/localiza/brasil/campinas-sao-paulo\n"
+ "/pt-br/locadora/localiza\n"
+ "/pt-br/locadora/localiza/brasil\n"
+ "/pt-br/locadora/localiza/estaasdasd/bananas";
final Pattern pattern = Pattern.compile(regex);
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