Regular Expression | REGEX for ICD9 codes

I am using Python to extract ICD9 codes. And I am using the following regex

icdRegex = recomp('V\d{2}\.\d{1,2}|\d{3}\.\d{1,2}|E\d{3}\.\d')

      

It fixes a pattern similar to 137.98 or V35.62

Everything works fine, except that the expression also captures the patient's weights as ICD9 code.

Now what I have observed, the weight almost always appears as if: 110.67 kg or kg or lb or lb

How to separate ICD9 from weight !?

+3


source to share


2 answers


Add a negative expression as a title:



(V\d{2}\.\d{1,2}|\d{3}\.\d{1,2}|E\d{3}\.\d)\b(?!\s?(?:lb|kg)s?)

      

+1


source


Here's a HamZa expression for everyone:

icdRegex = recomp("\b(?:V\d{2}\.\d{1,2}|\d{3}\.\d{1,2}|E\d{3}\.\d)\b(?!\s*(?:kg|lb)s?\b)")

      



Thanks to HamZa and Chapelo for their help. Appreciate this.

+1


source







All Articles