{"slug": "regular-expressions-for-hcpcs-codes", "title": "Regular expressions for HCPCS codes", "summary": "John D. Cook published a blog post on September 23, 2022, detailing regular expressions for matching HCPCS (Healthcare Common Procedure Coding System) Level II codes, which follow the format of one letter and four digits. He provides a regex pattern that matches all valid codes and optional modifiers, noting that a regex search took 20 milliseconds compared to 46 seconds for an exhaustive list search. Cook also warns that AI-generated information about HCPCS codes can be unreliable, citing a hallucinated claim about a D code for dentistry.", "body_md": "Since I revisited my old post on ICD code matching, I thought I’d revisit by [post on HCPCS codes](https://www.johndcook.com/blog/2022/09/23/hcpcs-codes/) too.\n\nHCPCS stands for Healthcare Common Procedure Coding System, and is pronounced “hick picks.” When most people say HCPCS, they technically mean HCPCS Level II, and that’s what I mean here.\n\nThe format of a HCPCS code is simple: one letter and four digits. In regex terms,\n\n```\n    [A-Z]\\d{4}\n```\n\nNot all letters are used, so you can get more specific and say\n\n```\n    [A-CEGHJ-MP-V][0-9]\\d{4}\n```\n\nSome sources say no codes begin with U, but there are currently five codes that begin with U.\n\nWhen I was doing some research on HCPCS codes recently using AI, I was told there is a D code for dentistry, but that was a hallucination.\n\nHCPCS codes can also have modifiers. These consist of a letter and either a letter or digit:\n\n```\n    [A-Z][A-Z0-9]\n```\n\nNot all letters actually appear in modifiers—I, O, W, and Y are missing—so you could be more specific. At the time of writing there are 384 official modifiers.\n\nModifiers are often stored in a separate column in a database, but in text you’ll see a HCPCS code optionally followed by a dash and a modifier. So a regex to match HCPCS codes with possible modifiers would be\n\n```\n    [A-CEGHJ-MP-V][0-9]\\d{4}(-[A-Z][A-Z0-9])?\n```\n\nThis regex will have some false positives, but it should not have false negatives: every real HCPCS code should match.\n\nOf course you could search against a complete list of HCPCS codes. This would be more accurate and slower. I did a test similar to the one in the [previous post](https://www.johndcook.com/blog/2026/07/17/regex-speed-error/) and found a search with the regex above took 20 milliseconds, while a search against the list of HCPCS codes took 46 seconds.\n\nHowever, the regex searched for possible modifiers and the exhaustive search only looked for unmodified HCPCS codes. A complete list of HCPCS codes with possible modifiers would be tedious to create because some combinations of codes and modifiers make no sense. And I imagine that some combinations that would make sense are not used in practice.", "url": "https://wpnews.pro/news/regular-expressions-for-hcpcs-codes", "canonical_source": "https://www.johndcook.com/blog/2026/07/17/regular-expressions-for-hcpcs-codes/", "published_at": "2026-07-17 14:02:52+00:00", "updated_at": "2026-07-31 19:17:42.123782+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["John D. Cook", "HCPCS"], "alternates": {"html": "https://wpnews.pro/news/regular-expressions-for-hcpcs-codes", "markdown": "https://wpnews.pro/news/regular-expressions-for-hcpcs-codes.md", "text": "https://wpnews.pro/news/regular-expressions-for-hcpcs-codes.txt", "jsonld": "https://wpnews.pro/news/regular-expressions-for-hcpcs-codes.jsonld"}}