PIIPatterns
Regex patterns for detecting Personally Identifiable Information (PII).
These patterns are designed for common US formats, plus international phone numbers written with a leading + and 15-digit American Express card numbers, and can detect:
- Social Security Numbers (SSN)
- Credit Card Numbers
- Email Addresses
- Phone Numbers
- IP Addresses
- Passport Numbers
- Driver's License Numbers
- Bank Account Numbers
- Medical Record Numbers
Note: These patterns favor recall over precision - they may have false positives but minimize false negatives for security-sensitive use cases.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PIIPatterns.type
Members list
Type members
Classlikes
Represents a detected PII match with type and location.
Represents a detected PII match with type and location.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Types of PII that can be detected.
Types of PII that can be detected.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object BankAccountobject CreditCardobject DateOfBirthobject Emailobject IPAddressobject Passportobject Phoneobject SSNShow all
Value members
Concrete methods
Check if text contains any PII.
Check if text contains any PII.
Value parameters
- text
-
Text to scan
- types
-
PII types to detect
Attributes
- Returns
-
True if any PII found
Detect all PII matches in text using specified patterns.
Detect all PII matches in text using specified patterns.
The types are matched independently, so text that two types match (a nine-digit run is both SSN- and passport-shaped) is returned, and counted, once per type. A finding is one match of one type: the number of findings is not the number of distinct stretches of PII, and maskAll writes one placeholder for an overlapping stretch. Derive distinct stretches from the indices when that is what you need.
Value parameters
- text
-
Text to scan
- types
-
PII types to detect (default: SSN, CreditCard, Email, Phone)
Attributes
- Returns
-
Sequence of matches with type and location
Mask all PII in text with redaction placeholders.
Mask all PII in text with redaction placeholders.
The types are matched independently, so two of them can match overlapping stretches of the text (a plain 15-digit card number is also a bank-account-shaped run of digits, and a phone number can run into the email address that follows it). Matches that overlap are merged into one stretch that is replaced once, so no character of either survives; it takes the placeholder of the match that starts first, the longest on a tie and the earlier of types after that.
Value parameters
- text
-
Text to scan and mask
- types
-
PII types to mask
Attributes
- Returns
-
Text with PII replaced by [REDACTED_*] placeholders
Get a summary of PII found in text.
Get a summary of PII found in text.
Counts detect's matches by type, so text that two types match counts once for each (see detect): the sum of the counts is how often the patterns fired, not how many placeholders maskAll would write.
Value parameters
- text
-
Text to scan
- types
-
PII types to detect
Attributes
- Returns
-
Map of PII type name to count