REGEXVAULTv2.0
Security/API Keys & Tokens
Verified Safe

Twilio Auth Token / SID Regex for Java

/^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$/i

What this pattern does

This page provides a well-structured, multi-part regular expression for matching twilio auth token / sid, ported and verified for Java. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. 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

Java
// Twilio Auth Token / SID
// ReDoS-safe | RegexVault — Security > API Keys & Tokens

import java.util.regex.Pattern;

public class TwilioAuthTokenSidValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4AC_short
SKa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4BCa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4X

When to use this pattern

This pattern is drawn from the Security > API Keys & Tokens 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

Twilio Auth Tokens are the master credential — prefer API Keys with limited scope. A leaked Auth Token allows sending bulk SMS from your account, triggering massive charges and potential spam reports.

Technical Notes

Twilio Account SID: AC + 32 hex chars. Auth Token: 32 hex chars (no prefix). API Key SID: SK + 32 hex chars. Auth Tokens have full account access. API Keys can be scoped and are preferred over Auth Tokens.

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