Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What about a pattern like this:</p> <pre><code>.*?\((CPT|ICD)-[A-Z0-9.]+\) </code></pre> <p>This will match zero or more of any character, non-greedily, followed by a <code>(</code> followed by either <code>CPT</code> or <code>ICD</code>, followed by a hyphen, followed by one or more Uppercase Latin letters, decimal digits or periods, followed by a <code>)</code>.</p> <p>Note that I picked <code>[A-Z0-9.]+</code> because, to my understanding, all current <a href="http://en.wikipedia.org/wiki/List_of_ICD-9_codes" rel="nofollow">ICD-9 codes</a> , <a href="http://en.wikipedia.org/wiki/ICD-10" rel="nofollow">ICD-10 codes</a>, and <a href="http://en.wikipedia.org/wiki/Current_Procedural_Terminology" rel="nofollow">CPT codes</a> conform to that pattern.</p> <p>The C# code might look a bit like this:</p> <pre><code>var result = Regex.Matches(input, @".*?\((CPT|ICD)-[A-Z0-9.]+\)") .Cast&lt;Match&gt;() .Select(m =&gt; m.Value); </code></pre> <p>If you want to avoid having any surrounding whitespace, you simply trim the result strings (<code>m =&gt; m.Value.Trim()</code>), or ensure that the matched prefix starts with a non-whitespace character by putting a <code>\S</code> in front, like this:</p> <pre><code>var result = Regex.Matches(input, @"\S.*?\((CPT|ICD)-[A-Z0-9.]+\)") .Cast&lt;Match&gt;() .Select(m =&gt; m.Value); </code></pre> <p>Or using a negative lookahead if you need to handle inputs like <code>(ICD-100)(ICD-200)</code>:</p> <pre><code>var result = Regex.Matches(input, @"(?!\s).*?\((CPT|ICD)-[A-Z0-9.]+\)") .Cast&lt;Match&gt;() .Select(m =&gt; m.Value); </code></pre> <p>You can see a working <a href="http://regexpal.com/?flags=g&amp;regex=%28%3F!%5Cs%29.%2a%3F%5C%28%28CPT%7CICD%29-%5BA-Z0-9.%5D%2B%5C%29&amp;input=SENSORINEURAL%20HEARING%20LOSS%20BILATERAL%20%28MILD%29%20%28ICD-389.18%29%20RIGHT%20WRIST%20GANGLION%20CYST%20%28ICD-727.41%29%20S%2FP%20INJECTION%20OF%20DEPO%20MEDROL%20INTO%20LEFT%20SHOULDER%20JOINT%20%28CPT-20600%29" rel="nofollow">demonstration here</a>.</p>
 

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