title: Using regex to define masks for numbers in Java
body: <p>I am trying to define a set of rules, that will compute a mask based on the number it is given. For example I am trying to return a mask of 8472952424 of any number that start with 12, 13, 14, Or return 847235XXXX for any number that starts with 7 or 8.</p>
  
  <p>The input numbers are 4 digit Integers and the return is a String. Do I need to convert the integers to string before I do the regex on them, and I am also not sure how to construct the expressions. </p>
  
  <p><strong>Edit</strong>
  I have too much criteria to be done using separate if statements for each case. I am matching extension numbers to masks so it could be inserted correctly on Cisco CallManager database (in case you are curious)</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is what I have done for one of the cases but this is still not matching correctly:</p>
  
  <pre><code>public String lookupMask(int ext){
     //convert to String
     StringBuilder sb = new StringBuilder();
     sb.append(ext);
     String extString = sb.toString();
  
     //compile and match pattern
     Pattern p = Pattern.compile("^[12|13|14|15|17|19|42]");
     Matcher m = p.matcher(extString);
     if(m.matches()){
         return "8472952424";
     }
     return null;
  }
  </code></pre>