fork(1) download
  1. import java.util.regex.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String inputStr = "Hi, Your Mobile no. is: 9876499321. Also, +919876499321 or 919876499321 or 09-876499321.";
  11. String myregex = "(?<!\\d)\\d{10,14}(?!\\d)";
  12. Pattern pattern = Pattern.compile(myregex);
  13. Matcher matcher = pattern.matcher(inputStr.replace("-", ""));
  14.  
  15. while(matcher.find()) {
  16. System.out.println(matcher.group());
  17. }
  18. }
  19. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
9876499321
919876499321
919876499321
09876499321