title: java regex to mask credit card details in log
body: <p>Here is my request string that is currently being printed in the server log. </p>
  
  <pre><code>PaymentRequest{Id=123456, type=CREDIT_CARD, creditCardDetails=CreditCardDetails{type=VISA, name=Some Name, number=1234567890123456, expiry=0316, CCV=000}, directDebitDetails=null}
  </code></pre>
  
  <p>I want to create a mask for the number field in the above request so that when it is printed in the log it looks like 123456789012--HIDDEN-- (the last 4 digits are replaced with 'HIDDEN').</p>
  
  <p>What java regex to create so that it robustly handles below situations?</p>
  
  <ul>
  <li>If [field=value] i.e. number=1234567890123456 is missing in the
  String.</li>
  <li>Credit card number could be of any length ranging from 0 to 16 e.g.
  number= OR number=0 or number=10 or number=1234567890123456.</li>
  <li>If number is less than 4 than final output is number=--HIDDEN--</li>
  <li>If number does not present i.e. number= than do nothing.</li>
  <li>number=1234567890123456 could either be in the middle e.g. ..., name=Some Name, number=1234567890123456}, ... or at last e.g. ..., number=1234567890123456, name=Some Name}, ...</li>
  </ul>