fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Pattern;
  5. import java.util.regex.Matcher;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String regex = "(?s)^.*(\\s(?<!\\d.)(?=\\d)|\\s(?<=\\d.)(?!\\d|\\s*$)|\\s(?<=[^\\d\\s].)(?=[^\\d\\s]))";
  13. String string = "jumnsch@domain.com m 5180-3807-3679-8221 612 3/1/2010\n\n"
  14. + "hello this card number 4444 5555 6666 7777\n\n"
  15. + "hello this bob";
  16.  
  17. Pattern pattern = Pattern.compile(regex);
  18. Matcher matcher = pattern.matcher(string);
  19.  
  20. if (matcher.find()) {
  21. System.out.println("[" + matcher.group(1) + "]");
  22. System.out.println(matcher.start(1));
  23. }
  24. }
  25. }
Success #stdin #stdout 0.15s 50880KB
stdin
Standard input is empty
stdout
[ ]
109