title: Mask credit card and pin from String in java
body: <p>Need to mask only 14 digit Credit card number and pin using regular expressions</p>
  
  <pre><code>import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  public class Mask{ 
      static String text="+919913623683,,,,1,2,,,4328798712363938,,,,5673,,7,8";
      public static void main(String[] args){
          System.out.println(replaceCreditCardNumber(text));
      }
      public static String  replaceCreditCardNumber(String text){
      String result = text.replaceAll("(\\d{16}(\\b([0-9]{4})[0-9]{0,9}([0-9]{4})\\b))", "$1--HIDDEN--,");
  return result;
  }
  }
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>String text="+919913623683,,,,1,2,,,4328798712363938,,,,5673,,7,8";
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>data="+919913623683,,,,1,2,,,************3988,,,,****,,7,8";
  </code></pre>