Guides

Custom Patterns

Create custom regex patterns to detect proprietary PII formats specific to your organization. Available on Professional and Enterprise tiers.

Professional+ Feature: Custom patterns are available on Professional (up to 50 patterns) and Enterprise (unlimited) tiers.

Pattern Structure

Each custom pattern consists of:

json
{
  "name": "CUSTOMER_ID",           // Unique identifier (alphanumeric + underscores)
  "pattern": "CUS-[A-Z]{2}[0-9]{6}", // JavaScript regex pattern
  "description": "Internal customer identifier format"  // Optional description
}

name

A unique identifier for the entity type. Must be alphanumeric with underscores, max 32 characters. This name will appear in redacted output as [CUSTOMER_ID].

pattern

A valid JavaScript regex pattern. Max 500 characters. Don't include the leading and trailing slashes or flags—we handle those automatically.

description

Optional human-readable description of what this pattern matches.

Example Patterns

Customer ID

Match internal customer identifiers like "CUS-AB123456"

json
{
  "name": "CUSTOMER_ID",
  "pattern": "CUS-[A-Z]{2}[0-9]{6}",
  "description": "Format: CUS-XX000000"
}

Employee Badge Number

Match employee badge numbers like "EMP-2024-00123"

json
{
  "name": "EMPLOYEE_BADGE",
  "pattern": "EMP-[0-9]{4}-[0-9]{5}",
  "description": "Format: EMP-YYYY-NNNNN"
}

Internal Project Code

Match project codes like "PROJ-ALPHA-2024"

json
{
  "name": "PROJECT_CODE",
  "pattern": "PROJ-[A-Z]{3,10}-[0-9]{4}",
  "description": "Internal project identifier"
}

Medical Record Number

Match custom MRN format like "MRN:12345678"

json
{
  "name": "CUSTOM_MRN",
  "pattern": "MRN:[0-9]{8}",
  "description": "Custom medical record number format"
}

Adding Patterns to Policies

Add custom patterns when creating or updating a policy:

json
// Create policy with custom patterns
POST /api/policies
Content-Type: application/json

{
  "name": "Healthcare Policy",
  "entity_types": ["PERSON", "SSN", "EMAIL"],
  "custom_patterns": [
    {
      "name": "CUSTOM_MRN",
      "pattern": "MRN:[0-9]{8}",
      "description": "Medical record number"
    },
    {
      "name": "PATIENT_ID",
      "pattern": "PT-[A-Z]{3}-[0-9]{6}",
      "description": "Patient identifier"
    }
  ],
  "redaction_format": "hash"
}

Regex Best Practices

Be Specific

Use precise patterns to avoid false positives. CUS-[A-Z]{2}[0-9]{6}is better than CUS-.*.

Use Word Boundaries

Add \b at the start and end to match whole words only:\bCUS-[A-Z]{2}[0-9]{6}\b

Escape Special Characters

Escape dots, brackets, and other regex metacharacters:192\.168\.1\.[0-9]{1,3}

Test First

Use the built-in pattern tester in the dashboard to verify your patterns match expected values before saving.

Keep It Simple

Complex patterns slow down detection. If you need complex logic, consider multiple simpler patterns.

Common Regex Constructs

PatternMeaningExample Match
[0-9]{6}Exactly 6 digits123456
[A-Z]{2,4}2-4 uppercase lettersAB, ABC, ABCD
[A-Za-z0-9]+One or more alphanumericAbc123
\d{3}-\d{4}Digits with dash123-4567
\b\w+\bWhole wordword
(?:USD|EUR)\d+Non-capturing groupUSD100, EUR50

Limits

  • Professional: Up to 50 custom patterns per policy
  • Enterprise: Unlimited custom patterns
  • Pattern length: Maximum 500 characters
  • Name length: Maximum 32 characters (alphanumeric + underscore)