fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11.  
  12. String regex = "(?<!^\\d{2})\\d(?=[\\d-]*\\d-?\\d-?\\d$)";
  13. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  14. String strings[] = { "7108898787654351", "7108-8987-8765-4351"};
  15.  
  16. for (String s : strings) {
  17. Matcher matcher = pattern.matcher(s);
  18. System.out.println(matcher.replaceAll("*"));
  19. }
  20. }
  21. }
Success #stdin #stdout 0.07s 33972KB
stdin
Standard input is empty
stdout
**0**********351
**0*-****-****-*351