fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String regex = "^[a-zA-Z]+ ((?:\\d{11}|\\d{14})|(?:\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2}|\\d{3}\\d{3}\\d{3}\\-\\d{2})|(?:\\d{2}\\.\\d{3}.\\d{3}\\/\\d{4}-\\d{2}|\\d{2}\\d{3}\\d{3}\\d{4}-\\d{2})\\b)";
  13. final String string = "Testing 42702434884 \n"
  14. + "Testing 064352729-13\n"
  15. + "05.994.401/0001-53\n"
  16. + "Testing 134.632.125-03";
  17.  
  18. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  19. Matcher matcher = pattern.matcher(string);
  20.  
  21. while (matcher.find()) {
  22. System.out.println(matcher.group(1));
  23. }
  24. }
  25. }
Success #stdin #stdout 0.08s 33980KB
stdin
Standard input is empty
stdout
42702434884
064352729-13
134.632.125-03