fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. final String regex = "\\G\\W*+(?:(?:vencimiento\\W+)?+\\w+\\W+)*?([0-3]?\\d[-/][01]?\\d[-/]\\d{4}\\b)";
  9. final String texto = "fecha vencimiento 20-12-2017\nfecha 20-12-2017\notra: 12/05/2016";
  10.  
  11. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  12. final Matcher matcher = pattern.matcher(texto);
  13.  
  14. if (matcher.find()) {
  15. do {
  16. System.out.println("Fecha: " + matcher.group(1));
  17. } while (matcher.find());
  18. } else {
  19. System.out.println("No se encontrĂ³ ninguna fecha");
  20. }
  21. }
  22. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Fecha: 20-12-2017
Fecha: 12/05/2016