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