Regex PII Detection: Why Patterns Miss Sensitive Data

Last updated: 24 October 2026
A regular expression matches a character shape. It cannot tell whether a 12-digit string is an Aadhaar number, an invoice number or a phone number written with its country code, and it cannot see personal data that has no fixed shape, such as a name or a diagnosis in a support ticket. Precision improves when the pattern is backed by a checksum, keywords found nearby, surrounding context and a confidence score that sends doubtful matches to a person. Microsoft Purview documents this same model for its sensitive information types (Microsoft Learn).
Source: IQWorks | Last updated: October 2026
Microsoft describes its sensitive information types as "pattern-based classifiers", and its Aadhaar definition already needs more than a pattern to reach high confidence: a check digit that passes and a keyword within 300 characters (Microsoft Learn, Aadhaar entity definition). Regex PII detection means finding personal data by matching text against regular expressions, patterns that describe how an identifier looks. We treat a regex hit as a candidate to be confirmed: used alone, patterns overflag look-alike numbers and miss personal data written as prose. This guide is for CISOs, security engineers and data governance leads who run scanners or DLP.
How regex-based detection works
Microsoft Purview documents its sensitive information types (SITs) in enough detail to serve as a reference model for pattern detection generally. Each SIT has a pattern made of four parts (Microsoft Learn, Learn about sensitive information types):
| Part | What it does | Example |
|---|---|---|
| Primary element | The thing being looked for. Purview says it "can be a regular expression with or without a checksum validation, a keyword list, a keyword dictionary, or a function" | A 12-digit pattern for Aadhaar |
| Supporting element | Corroborating evidence that raises confidence when found near the primary element | The word "Aadhaar" or "UID" nearby |
| Proximity | How many characters may separate the supporting and primary elements | 300 characters in the Aadhaar definition |
| Confidence level | High, medium or low, depending on how much supporting evidence was found | 85 (high) with keyword and checksum, 75 (medium) without the keyword |
According to Microsoft, high-confidence patterns return "the fewest false positives but might result in more false negatives", while low confidence returns "the most false positives" and the fewest false negatives, so raising the threshold to cut noise means accepting more missed personal data.
A regular expression based sensitive information type is a SIT whose primary element is a regular expression, usually tightened by a checksum and nearby keywords.
Where patterns fail
Same shape, different meaning
Purview's Aadhaar pattern is 12 digits, where the first digit is not 0 or 1 and the final digit is a check digit, with optional spaces or dashes between the groups of four (Microsoft Learn, Aadhaar).
Plenty of other 12-digit strings fit that shape:
- an order or invoice ID such as
4XXX XXXX XXXXfrom an e-commerce export; - an Indian mobile number stored with its country code and no plus sign, which gives 12 digits starting with 91;
- a bank reference, a policy number or a numeric timestamp.
A bare pattern flags all of them. The reverse case is harder: a real Aadhaar number in a column labelled ref_no looks no different from an order ID, so the shape can only tell you that a string might be an identifier, and the surrounding context has to settle whether it is one.
Valid format, invalid value
A checksum removes many look-alikes, because a string that only has the right length can fail the arithmetic.
- Purview's credit card type requires 14 to 19 digits that "must pass the Luhn test" and match the number formats of major card brands (Microsoft Learn, credit card).
- The Purview Aadhaar definition lists "Checksum: Yes", and both its high and medium confidence patterns need the checksum to pass.
- The Purview PAN definition describes 10 characters: three letters, a fourth letter from a fixed set (C, P, H, F, A, T, B, L, J, G), a fifth letter, four digits and a final letter it calls "an alphabetic check digit". It still lists "Checksum: No", so Purview does not validate that last character (Microsoft Learn, PAN).
Any string of the form XXXPX0000X with a valid fourth letter matches, so PAN detection relies on the keyword "PAN" or "Permanent Account Number" nearby to reach high confidence. Without it, Purview rates the match low. A passing checksum also proves only that the number is well formed. It does not prove the number was issued to anyone, or that the record belongs to a real person.
Personal data with no shape
Section 2(t) of the Digital Personal Data Protection Act, 2023 defines personal data as "any data about an individual who is identifiable by or in relation to such data" (DPDP Act, 2023, s.2(t)). That definition turns on identifiability, so data with no fixed format can still be personal data.

Much of what fits it has no pattern at all. A support ticket that reads "my husband's dialysis appointment was moved, please call me at home" contains health information about an identifiable person, and no regular expression will find it. Names, home addresses written out in words, salary discussions in HR email and loan details in chat transcripts are all personal data that shape-matching cannot see. Purview handles these with separate named entity types that detect person names, physical addresses and medical terms and conditions, alongside its pattern-based types.
Formatting drift
Real data rarely matches the format in the specification. Common variants include:
- separators that change between systems: spaces, dashes, dots, or none;
- numbers split across two columns or two lines of a scanned form;
- OCR errors that turn a 0 into an O or a 1 into an l;
- partly masked values such as
XXXX XXXX 1234, which are still personal data if the rest of the record identifies the person; - identifiers embedded inside longer strings, such as file names or URLs.
Each variant needs its own pattern or a normalisation step before matching. Teams that keep adding alternatives to one expression end up with patterns nobody can review, and false positives rise with every alternative.
Languages and scripts
Indian organisations hold personal data in many scripts, and in transliteration: a Hindi name typed in Latin letters, a Tamil address mixed with English, a form where labels are in one language and values in another. A keyword list in one language misses the others. Purview's own Aadhaar keyword list includes the Devanagari "आधार" alongside the English terms. Supporting evidence has to exist in the language the document uses. Transliteration multiplies the spellings a dictionary must hold.
What adds precision
Each technique removes a different class of error, so detectors combine them:
| Technique | What it removes | Its limit |
|---|---|---|
| Checksum validation | Random look-alikes of the right length | Only works where the identifier has a check digit; PAN validation in Purview has none |
| Keywords within a proximity window | Matches with no supporting context nearby | Misses real identifiers in unlabelled columns or terse logs |
| Context and NLP models | Shapeless personal data in prose; ambiguous numbers | Needs evaluation on your own documents and languages |
| Confidence scores with human review | Silent errors in the doubtful middle band | Creates a review queue someone must staff |
The table leaves two gaps, custom identifiers and inconsistent formatting. Two practices close them:
- Define custom data types for employee IDs, customer numbers and policy numbers. They are personal data in your organisation even though no public detector knows their format.
- Normalise inputs before matching. Strip separators, fix common OCR swaps and rejoin split fields before the pattern runs, so one expression covers many layouts.
For a side-by-side view of the two broad approaches, see rule-based vs AI classification. For the end-to-end workflow, the PII detection automation guide covers setup and tuning.
Why detection quality is a compliance issue
Data a scanner misses cannot be masked, logged or included in an access response, so the safeguards in s.8(5) and Rule 6 do not reach it.
Security safeguards under s.8(5) and Rule 6(1)
A Data Fiduciary (the organisation that decides why and how personal data is processed) must protect personal data in its possession or under its control "by taking reasonable security safeguards to prevent personal data breach" (DPDP Act, 2023, s.8(5)).
The DPDP Rules list the minimum measures, including "encryption, obfuscation, masking or the use of virtual tokens mapped to that personal data" (Rule 6(1)(a)), access control (Rule 6(1)(b)), and "visibility on the accessing of such personal data, through appropriate logs, monitoring and review" (Rule 6(1)(c)) (DPDP Rules, 2025, Rule 6). You can only mask or log access to data you have found. The DPDP Rules, 2025 (G.S.R. 846(E)) were notified in the Gazette dated 13 November 2025, and Rules 3, 5 to 16, 22 and 23 come into force on 13 May 2027 (Rule 1(4)).

Access requests under s.11(1)(a)
A Data Principal (the person the data is about) can ask for "a summary of personal data which is being processed" and the processing activities (DPDP Act, 2023, s.11(1)(a)). A summary built from a scanner that misses free text will be incomplete. Our guide to DSR workflows covers how teams locate data for these responses.
No special category in DPDP
The DPDP Act has no "sensitive personal data" category. It covers digital personal data as a whole (s.3), with added duties for children's data (s.9). Sensitivity appears once, as a factor the government may weigh when notifying a Significant Data Fiduciary: "the volume and sensitivity of personal data processed" (s.10(1)(a)). So the test for your scanner is whether it finds personal data, whatever its type.
GDPR Articles 9 and 32
The GDPR does define special categories, including data concerning health, sex life or sexual orientation, and religious or philosophical beliefs (GDPR Art. 9(1), EUR-Lex). These usually appear in prose, which is the hardest case for patterns. Article 32 requires controllers and processors to take measures "appropriate to the risk", naming "the pseudonymisation and encryption of personal data" among them.

Failing to take reasonable security safeguards under s.8(5) is entry 1 of the Schedule to the Act, with a penalty that may extend to ₹250 crore (p. 21).
How to test your current detection
You can measure your own tool without relying on vendor benchmarks.
- Build a seeded test set. Create documents and tables that contain synthetic identifiers you have generated yourself, including Aadhaar-shaped and card-shaped strings that pass and fail their checksums. Never use real identifiers. Add look-alikes: order IDs, phone numbers with country codes, reference numbers.
- Add shapeless personal data. Write support tickets, emails and chat transcripts with names, addresses and health or financial details in prose, in the languages and scripts your organisation uses.
- Add formatting variants. The same synthetic value with spaces, dashes, no separator, split across fields, partly masked and as a scanned image with OCR.
- Record ground truth. Mark every planted item and every decoy before you run the scan.
- Measure precision and recall. Precision is the share of flagged items that are truly personal data. Recall is the share of planted personal data the tool found. Report both per data type, because a good average can hide a type the tool never finds.
- Check confidence bands. See which true positives arrive at low confidence and which false positives arrive at high confidence. That tells you where your thresholds sit.
- Measure the review load. Count how many items land in the human review queue per thousand documents, and estimate the reviewer hours that implies at your real data volume.
- Repeat after changes. Rerun the same set after every rule or model change so you can see regressions.
Keep the results. They are evidence that your safeguards rest on a tested inventory, which is useful when a DPO, an auditor or the Board asks how you know where personal data sits.
Common mistakes with pattern-based detection
- Treating a match count as an inventory. Ten thousand Aadhaar-shaped hits may be mostly order IDs, so count confirmed findings.
- Raising confidence to silence noise. Microsoft's documentation states that higher thresholds cut false positives and increase misses.
- Scanning only structured stores. Email, tickets, shared drives and chat exports are where shapeless personal data tends to sit, and they are often left out of scope.
- Ignoring custom identifiers. Employee and customer numbers are personal data in context, and no off-the-shelf pattern knows them.
- Testing on clean samples. A detector tuned on tidy CSVs will fail on scanned forms and mixed-script text.
Regex PII detection checklist
- Every identifier pattern with a check digit (cards, Aadhaar) validates the checksum as well as the format.
- Patterns without a checksum (PAN, phone numbers) require a supporting keyword before a match counts as high confidence.
- Keyword lists cover the languages and scripts your documents use, including transliterated forms.
- Inputs are normalised for separators, OCR swaps and split fields before matching.
- Custom types exist for employee IDs, customer numbers and other in-house identifiers.
- Free-text sources (email, tickets, chat, shared drives) are in scope, with a context-aware method for shapeless data.
- Each finding carries a confidence score, and low-confidence findings go to a named reviewer.
- Reviewer decisions are recorded so the detection history can be shown later.
- A seeded synthetic test set is run after every rule or model change, with precision and recall reported per data type.
- Findings feed masking, access control and access logging under Rule 6(1)(a) to (c), and the s.11 access summary.
Related reading: one inventory that every privacy workflow reads from and carrying discovery results into a DSR response.
Key Takeaways
- A regular expression confirms shape. Checksums, nearby keywords, context and human review supply the meaning.
- Aadhaar and card numbers carry check digits that Purview validates. Its PAN definition describes a check character but lists "Checksum: No", so PAN needs a keyword.
- Personal data such as a name or a diagnosis in a support ticket has no fixed shape for a pattern to match, and the DPDP definition in s.2(t) covers it anyway.
- Under s.8(5) and Rule 6(1), safeguards such as masking and access logs depend on finding the data first.
- Test your tool on a seeded synthetic set and measure precision and recall per data type.
Frequently asked questions
Is regex enough to detect PII?
For fixed-format identifiers with check digits, such as card numbers, a regex plus checksum and keyword gives reasonable precision. It is not enough for personal data written in prose, which the DPDP Act still covers because s.2(t) turns on identifiability. Microsoft's own documentation calls its sensitive information types "pattern-based classifiers" and offers separate named entity types for names, addresses and medical terms.
What is a regular expression based sensitive information type?
It is a detection rule whose primary element is a regular expression, used in DLP and labelling tools such as Microsoft Purview. Supporting elements (keywords or further patterns) found within a set proximity raise its confidence level, and a checksum can be added. In Purview, confidence levels are high (85), medium (75) and low (65).
How do you detect Aadhaar numbers accurately?
Match 12 digits with an optional space or dash between groups, a first digit other than 0 or 1, and a final check digit that must pass validation. Then look for a keyword such as "Aadhaar", "UID" or "आधार" within about 300 characters, which is how Purview reaches high confidence. Test on synthetic values only, since Aadhaar numbers are personal data under s.2(t).
Does PAN have a checksum?
Microsoft's PAN definition describes the last character as "an alphabetic check digit", but lists "Checksum: No", so Purview does not validate it. In practice any string with three letters, a fourth letter from the permitted set, a fifth letter, four digits and a final letter will match. Rely on the "PAN" keyword nearby, then confirm in review before relying on findings for Rule 6(1) safeguards.
Does the DPDP Act have a sensitive personal data category?
No. The Act applies to digital personal data as a whole (s.3) and defines personal data by identifiability (s.2(t)). Children's data carries extra obligations under s.9. Sensitivity appears only in s.10(1)(a), as a factor for notifying a Significant Data Fiduciary. GDPR is different: Article 9 sets out special categories such as health data.
Does better detection reduce DPDP risk?
It supports the safeguards the law requires. Section 8(5) obliges reasonable security safeguards, and Rule 6(1)(a) and (c) name masking, encryption and access logs, all of which depend on knowing where personal data is. Failure to take reasonable safeguards is Schedule entry 1, with a penalty of up to ₹250 crore. Detection evidence also helps show your controls were reasonable.
The short version
Use regular expressions as a first pass. Validate check digits where they exist, require keywords where they don't, normalise formats, and add a context-aware method for personal data in prose and in Indian languages. Score every finding, review the doubtful ones and keep the record. Then test the whole chain on a seeded synthetic set so you can measure and show precision and recall. Once detection is reliable, the next step is acting on what it finds: see classification that acts on what detection finds, and for the question of where the data lives in the first place, AI-powered data discovery.
Where IQWorks fits
IQWorks splits this work across two products. Our PII discovery and classification page says "DiscoverIQ scans connected systems using NLP and pattern recognition to identify personal data in both structured and unstructured formats", and the DiscoverIQ page lets you "Define organization-specific data types beyond standard PII". The ClassifyIQ page describes "context-aware AI" that classifies data "based on meaning rather than simple pattern matching", and says "Every classification includes a confidence score, allowing human review of edge cases", with a "Complete history of classification decisions with reviewer actions". Test it on your own seeded set the same way you would test any other tool, and if you want to run that test on DiscoverIQ and ClassifyIQ, book a demo of DiscoverIQ and ClassifyIQ.

Our verdict
18 ratings, from Customer Success Research.
Free DPDP Implementation Workshop
A 90-minute session for your team, on-site or remote: the DPDP Act applied to your organization, a 90-day roadmap, and the top five actions per department.
Book the workshopRelated Solutions
Know where personal data lives and how risky it is, and label it by policy.


