fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String line = "Hello my 1st SSN : 11.333.56.3788 , 2nd SSN: 333-56-3789 , 3rd SSN 333.56.3780" ;
  11. Pattern p = Pattern.compile("(?<!\\d|\\d[.-])\\d{3}(?=([.-]))\\1\\d{2}\\1\\d{4}(?![.-]?\\d)");
  12. Matcher m = p.matcher(line);
  13. while(m.find()) {
  14. System.out.println(m.group() );
  15. }
  16. }
  17. }
Success #stdin #stdout 0.08s 33776KB
stdin
Standard input is empty
stdout
333-56-3789
333.56.3780