By · Last updated 2026-05-29

Back to BlogHealthcare

HIPAA MRN Detection Without a Regex PhD

Every hospital's MRN format is different. Memorial uses MRN:XXXXXXX, St. Mary's uses PT-YYYYY, University Hospital uses UHN-XXXXXXXXXX.

May 29, 20266 minute read
HIPAA de-identificationMRN patternhealthcare ITAI pattern generationPHI detection

HIPAA MRN Detection Without a Regex PhD

Your hospital's MRN format is not in any standard PII tool. Here is how to add it in five minutes. No code needed.

Healthcare IT teams face a HIPAA problem that other sectors do not have. The ID they most need to find — the Medical Record Number — is set by their own hospital. No national standard exists.

Every HIPAA de-ID project needs custom setup. Without it, MRNs slip through "de-identified" files undetected.

The Multi-Facility MRN Problem

Hospital networks built through mergers have legacy EHR systems. Each system has its own MRN format:

  • Memorial Hospital (Epic): MRN:XXXXXXX — 7-digit number with prefix
  • St. Mary's (Cerner): PT-YYYYY — 5-digit with patient prefix
  • University Hospital (Meditech): UHN-XXXXXXXXXX — 10-character mix
  • Clinic (standalone EMR): C\d{5} — letter C plus 5 digits

HIPAA Safe Harbor requires removing all 18 ID types. Category 8 is medical record numbers. A tool that does not know your format will miss them. The file looks clean. It is not.

The ServiceNow healthcare community has noted this exact issue. Standard tools catch SSNs and phone numbers. They miss facility MRNs every time.

The Regex Barrier

Adding custom rules to Microsoft Presidio — the open-source base for many HIPAA tools — takes real skill:

  • You need to know the PatternRecognizer class
  • You must write regex in Python syntax
  • You must set up YAML config files
  • You must tune confidence scores
  • You must test and debug Python scripts

A compliance officer who knows the MRN format cannot do this alone. The fix ends up as an engineering ticket. It sits in queue for 6–8 weeks. The gap stays open.

AI-Assisted Pattern Generation

There is a faster way. Describe the pattern in plain words. Get a working regex back.

Steps:

  1. Open the custom entity builder
  2. Give examples: "Our MRNs look like this: MRN:1234567, MRN:9876543, MRN:0001234"
  3. AI builds the rule: MRN:\d{7}
  4. Test on 10 sample records
  5. All MRNs found? Save and deploy.

For a network with four MRN formats:

  • Memorial Hospital → MRN:\d{7}
  • St. Mary's → PT-\d{5}
  • University Hospital → UHN-[A-Z0-9]{10}
  • Clinic → C\d{5}

Make four custom entities. Group them into a preset. Run on all files. Time: one afternoon.

See custom MRN detection in HIPAA pipelines without code for a full how-to guide.

Validation for Safe Harbor

HIPAA Safe Harbor says the covered entity must have no "actual knowledge" the data could identify someone. (45 CFR §164.514(b))

Validation shows your custom rules cover all 18 ID types.

Step 1: Pull samples. Get 100 records from each site. Mix time periods and departments.

Step 2: Run detection. Process all 400 documents with your custom rules.

Step 3: Human check. Review 20 documents by hand (5% sample). Look for missed MRNs and false hits.

Step 4: Refine rules. Missed MRNs? Broaden the pattern. Too many false hits? Add word boundaries.

Step 5: Write it down. Log the rule, the sample size, the results, and the date. This log is your Safe Harbor record.

See explainable redaction and HIPAA audit trails for more on what to document.

Full Safe Harbor Coverage

After fixing MRN detection, check all 18 categories.

CategoryStandard ToolsCustom Needed?
1. NamesNER modelNo
2. Geographic dataLocation detectionNo for state; Yes for site codes
3. DatesDate detectionNo
4. Phone numbersPhone detectionNo
5. Fax numbersPhone detectionNo
6. Email addressesEmail detectionNo
7. SSNsSSN detectionNo
8. Medical record numbersNot built inYes — site-specific
9. Health plan member numbersPartialOften yes — payer-specific
10. Account numbersPartialOften yes — billing format
11. License numbersPartialOften yes — state-specific
12. Vehicle IDsPartialRare in clinical docs
13. Device IDsPartialYes if devices are in records
14. Web URLsURL detectionNo
15. IP addressesIP detectionNo
16. Biometric IDsText contextRare in discharge notes
17. PhotosImage onlyOut of scope for text
18. Other unique IDsNot built inYes — site-specific

For clinical text, categories 8, 9, 10, and 18 most often need custom setup.

Clinical Document Context

Discharge notes, clinical notes, and op reports are the main files shared for research. They hold:

  • MRNs in headers and footers
  • Account numbers in billing sections
  • Dates for all events — admit, procedure, lab, med
  • Physician names and DEA numbers
  • Referring doctor info
  • Insurance member IDs

Custom rules for site-specific formats pair with built-in rules for standard formats. That pair gives you full Safe Harbor coverage.

Conclusion

HIPAA de-ID without custom rules is not Safe Harbor de-ID. Every hospital's MRN format is unique. Standard tools miss them. The compliance gap is real and it stays open until you close it.

AI pattern generation cuts the fix from 6–8 weeks of engineering to one afternoon of compliance work. Describe the format. Test it on real records. Deploy it. Done.

Sources

Ready to protect your data?

Start anonymizing PII with 285+ entity types across 48 languages.

About this page

We update this page when our platform or the law changes.

Read our founder note for how we work.

Each change shows up in the timestamp at the top.

Related reading

We follow these rules

  • GDPR (EU 2016/679).
  • ISO/IEC 27001:2022.
  • NIS2 (EU 2022/2555).
  • HIPAA safe harbor under 45 CFR § 164.514(b)(2).

Our promise

We do not sell your data.

We do not train models on your text.

We store your files in Germany.

You can delete your account at any time.

You own your work.

Where we run

Our servers live in Falkenstein, Germany.

We use Hetzner. They hold ISO 27001 certification.

All data stays in the EU.

Backups run every day.

Need help?

Email support@anonym.legal.

We reply within one business day.

How we test

We run a full check suite on every release.

Each surface gets its own sweep script and report.

Human reviewers spot-check the output each week.

We track recall and precision on a labelled set.

Bad runs block the deploy.

What we never do

  • We never sell your information to third parties.
  • We never train models on what you upload.
  • We never keep your work after you delete it.
  • We never share keys with any outside firm.
  • We never run ads inside the product.

Plans in plain words

We sell credits, not seats.

One credit covers one short job.

Long jobs use a few credits each.

You can top up at any time.

Unused credits roll over each month.

Read the plans page for current rates.

Who built this

A small team of engineers and lawyers built this.

We ship from Europe and work in the open.

Our founder note spells out why we started.

Where to start

How the parts fit

A browser add-on cleans text inside Chrome.

A Word plug-in handles drafts in Office.

A small desktop tool works on whole folders.

An agent protocol link feeds large models safely.

All four share one core engine and one rule set.

Words from our team

We started this work after a lunch about cookies.

One friend kept getting odd ads on her phone.

We asked why a court file leaked through a draft.

We sketched the first build on a napkin that week.

By month three we had a tiny demo for a friend.

She used it on her first case the next day.

Common questions we hear

Can the tool read scanned PDFs? Yes, with OCR.

Does it work on long files? Yes, in small chunks.

Can I roll my own rule set? Yes, save it as a preset.

Does it run offline? The desktop build runs offline.

Do you keep my files? No, the cloud build wipes after each run.

Will it learn from my work? No, we never train on inputs.

A short tour of the workflow

Upload a file or paste a snippet of prose.

Pick the entities you want gone from the draft.

Choose a method: replace, mask, hash, encrypt, or redact.

Press run and watch the side panel show each hit.

Skim the result and tweak any rule that misfired.

Save the cleaned file or send it to a teammate.