Only match unique string occurrences
<p>We are doing some Data Loss Prevention for emails, but the issue is when people reply to emails multiple times sometimes the credit card number or account number will appear multiple times.</p>

<p>How can we get Java Regex to only match strings once each.</p>

<p>So for example, we are using the following regex to catch account numbers that match 2 letters followed by 5 or 6 numbers. it will also omit CR in either case.</p>

<pre class="lang-regex prettyprint-override"><code>\b(?!CR)(?!cr)[A-Za-z]{2}[0-9]{5,6}\b
</code></pre>

<p>How can we have it find:</p>

<pre class="lang-none prettyprint-override"><code>CX12345
CX14584
JB145888
JD748452
CX12345 (Ignore as its already found it above)
LM45855
</code></pre>