Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching for patterns in String, and removing
    primarykey
    data
    text
    <p>I have been tasked with going through a large list of string values, and removing any sign of credit cards. So, if, within the string, I find anything that matches (where n = numerical):</p> <pre><code>nnnn nnnn nnnn nnnn (4 x 4 numerical) nnnnnnnnnnnnnnnn (16 numerical) nnnn-nnnn-nnnn-nnnn (Hyphened) nnnn nnnnnn nnnn (American express?) nnnnnnnnnnnnnn (AX, no spaces) nnnn-nnnnnn-nnnn (AX, Hyphened) </code></pre> <p>I need to replace that part of the string with <code>[CARD NUMBER REMOVED]</code></p> <p>So,</p> <pre><code>"Client called and gave credit card details as 1234123412341234, exp 1201, and will be booked next week" </code></pre> <p>would become:</p> <pre><code>"Client called and gave credit card details as `[CARD NUMBER REMOVED]`, exp 1201, and will be booked next week" </code></pre> <p>I'm thinking RegEx would FIND this, but I have zero regex experience, and there are many patterns. And, how do I replace that portion?</p> <p>I could write something that iterates through each char and does some rule checking, but that seems hacky.</p> <p>Any ideas?</p> <p>I am trying this:</p> <pre><code> const string pattern = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$"; const string replacement = "[CARD DETAILS REMOVED]"; var rgx = new Regex(pattern); string cleansedText = rgx.Replace(UncleansedText, replacement); return cleansedText; </code></pre> <p>But it doesn't seem to find a match in this:</p> <p>"1234610008918730^^9-11^^Code 064^"</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload