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