title: How to mask credit card number mask in a text?
body: <p>I have a form on my website and my customers send message to me with this form. Sometimes they write their credit card number on the message. So this is really critical. I want to mask these credit card numbers. But of course card numbers don't come on a regular basis.</p>
  
  <blockquote>
    <p>Example 1: 1111222233334444</p>
    
    <p>Example 2: 4444 3333 2222 1111</p>
    
    <p>Example 3: 4444-3333-2222-1111</p>
    
    <p>Example 4: 4444 - 3333 - 2222 - 1111</p>
    
    <p>Example 5: 4444--3333--2222--1111</p>
  </blockquote>
  
  <p>So I can mask for example 1, 2 and 3. But if there are more than one space or dash between numbers I can't.</p>
  
  <p>And this is my last regex:</p>
  
  <pre><code>preg_replace("/(?:\b| )([3456]\d{3})([ -]+){0,1}\d{4}([ -]+){0,1}\d{4}([ -]+){0,1}(\d{0})/", "$1********$2", $a1);
  </code></pre>
  
  <p>And results for this regex:</p>
  
  <blockquote>
    <p>Result 1: 4444********1111</p>
    
    <p>Result 2: 4444******** 1111</p>
    
    <p>Result 3: 4444********-1111</p>
    
    <p>Result 4: 4444******** - 1111</p>
    
    <p>Result 5: 4444********--1111</p>
  </blockquote>
  
  <p>So what should I do in regex? Thanks.</p>