title: Regex to mask a PhoneNumber
body: <p>I need to mask the phonenumber so that result is</p>
  
  <pre><code> (***)-(***)-XXXX
  </code></pre>
  
  <p>XXXX being the last 4 digits of number.</p>
  
  <p>Right now my code is </p>
  
  <pre><code> String mask = phoneNumber.replaceAll("(?&lt;=.).(?=[^-()]*?.-)", "*");
  </code></pre>
  
  <p>Result is (***)***X-XXXX. </p>
  
  <pre><code>  String mask1 = phoneNumber.replaceAll("(?:[^()-])", "*");
  </code></pre>
  
  <p>Result is    </p>
  
  <pre><code> (***)-***-**** 
  </code></pre>
  
  <p>I am not able to know what mistake I am making.</p>