Data Subject Request (DSR) Reference Number Regex for Java
/^(?:DSR|DSAR|SAR|RTF|RTE|REC)[\-][0-9]{4}[\-][0-9]{4,8}$/iWhat 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 Java. 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 Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.
Java Implementation
// Data Subject Request (DSR) Reference Number
// ReDoS-safe | RegexVault — Identity & PII > Consent & Compliance
import java.util.regex.Pattern;
public class DataSubjectRequestDsrReferenceNumberValidator {
private static final Pattern PATTERN =
Pattern.compile("^(?:DSR|DSAR|SAR|RTF|RTE|REC)[\\-][0-9]{4}[\\-][0-9]{4,8}$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("DSR-2024-00001234")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
DSR-2024-00001234 | 2024-00001234 |
DSAR-2024-12345678 | DSR2024-00001234 |
SAR-2024-0001 | DSR-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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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