fork(2) 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. List<String> strs = Arrays.asList("*123#","*1*2*3#","*1#23#","***123###","*12**3#");
  11. Pattern pat = Pattern.compile("(?:\\*\\d+)+#");
  12. for (String str : strs) {
  13. System.out.println(str + ": " + pat.matcher(str).matches());
  14. }
  15.  
  16.  
  17. }
  18. }
Success #stdin #stdout 0.1s 28024KB
stdin
Standard input is empty
stdout
*123#: true
*1*2*3#: true
*1#23#: false
***123###: false
*12**3#: false