REGEXVAULTv2.0
Identity & PII/Consent & Compliance
Verified Safe

Data Subject Request (DSR) Reference Number Regex for Python

/^(?:DSR|DSAR|SAR|RTF|RTE|REC)[\-][0-9]{4}[\-][0-9]{4,8}$/i

What this pattern does

This page provides a well-structured, multi-part regular expression for matching data subject request (dsr) reference number, ported and verified for Python. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# Data Subject Request (DSR) Reference Number
# ReDoS-safe | RegexVault — Identity & PII > Consent & Compliance

import re

data_subject_request_dsr_reference_number_pattern = re.compile(r'^(?:DSR|DSAR|SAR|RTF|RTE|REC)[\-][0-9]{4}[\-][0-9]{4,8}$')

def validate_data_subject_request_dsr_reference_number(value: str) -> bool:
    return bool(data_subject_request_dsr_reference_number_pattern.fullmatch(value))

# Example
print(validate_data_subject_request_dsr_reference_number("DSR-2024-00001234"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
DSR-2024-000012342024-00001234
DSAR-2024-12345678DSR2024-00001234
SAR-2024-0001DSR-24-00001234
DSR-2024-ABCD

When to use this pattern

This pattern is drawn from the Identity & PII > Consent & Compliance category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

GDPR requires responding to DSARs within 30 calendar days (extendable to 90 days for complex requests, with notification). Tracking the DSR number in a workflow system is essential for compliance. Never dismiss a DSAR as spam without logging receipt.

Technical Notes

DSR reference formats: DSR=Data Subject Request, DSAR=Data Subject Access Request, SAR=Subject Access Request (UK), RTF=Right to Forget, RTE=Right to Erasure, REC=Rectification. Year prefix allows filtering by year. Sequential number ensures uniqueness.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern