fork(1) download
  1. /*
  2. // Expresiones regulares en java
  3. // https://es.stackoverflow.com/q/145363/127
  4. */
  5.  
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. final String regex = "\\b[A-Z\\d]{1,2}(?:-\\d{1,4}){2}\\b";
  14. final String cleanpageone = "PE-13-641 N-12-1236 1-11-778";
  15.  
  16. final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  17. final Matcher matcher = pattern.matcher(cleanpageone);
  18.  
  19. while (matcher.find()) {
  20. System.out.println(matcher.group(0));
  21. }
  22. }
  23. }
Success #stdin #stdout 0.09s 27788KB
stdin
Standard input is empty
stdout
PE-13-641
N-12-1236
1-11-778