import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\b(.+)(?:\\n.*)(?:relatora?|desembargadora?|ju[íi]za?)";
final String string = "2. dispositivo\n\n"
+ "luiza carla g. godoi\n"
+ " juíza\n\n"
+ "acordam os magistrados da 2ª turma do \n"
+ "tribunal regional do trabalho da 2ª região em: não \n"
+ "na forma da \n"
+ "do agravo de instrumento, \n\n"
+ "luiz carlos g. godoi\n"
+ " desembargador\n\n"
+ "conhecer \n\n"
+ "fundamentação do voto do relator.\n\n"
+ "luiz carlos g. godoi\n"
+ " relator\n\n"
+ "§01918.2007.501.02.01-0 (brl53010)\n\n"
+ "documento elaborado e assinado em meio digital. validade legal nos termos da lei n. 11.419/2006.(cid:13)\n"
+ "disponibilização e verificação de autenticidade no site www.trtsp.jus.br informando:\n"
+ "codigo do documento = 10017\n\n"
+ "luiza carla g. godoi\n"
+ " relatora\n\n\n"
+ "reclamada da ação trabalhista julgada \n"
+ "procedente em parte, está a agravante legitimada à \n"
+ "impugnação.\n\n"
+ "luiza carla g. godoi\n"
+ " desembargadora\n";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
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