35 patterns
Coding & Development Regex Patterns
Developer-specific regex patterns for validating and parsing common code artifacts. Whether you're parsing package versions, validating configuration keys, or extracting color values from CSS, these patterns handle the most frequent developer use cases.
Common Use Cases
All Coding & Development Patterns
camelCase Detection
Checks if a string is in camelCase format.
^[a-z]+(?:[A-Z][a-z]+)+$snake_case Detection
Checks if a string is in snake_case format.
^[a-z0-9]+(?:_[a-z0-9]+)*$PascalCase Detection
Checks if a string is in PascalCase format.
^[A-Z][a-z]+(?:[A-Z][a-z]+)*$JavaScript Identifier
Valid JS variable/function name.
^[A-Za-z_$][A-Za-z0-9_$]*$NPM Version Range
Validates NPM version ranges (^1.0.0, ~2.1.0, *).
^[~^]?\d+\.\d+\.\d+$|^\*$|^\d+\.x$Cron Expression
Validates basic Cron schedule expressions.
^((((\d+,)+\d+|(\d+(\/|-)\d+)|\*\/\d+|\d+|\*) ?){5,6})$Git Branch Name
Validates Git branch names (no .., no ending with .lock).
^(?!.*\.\.)[a-zA-Z0-9_./-]+(?<!\.lock)$GitHub Repository
Validates GitHub repository format (owner/repo).
^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$NPM Package Name
Validates NPM package names (including scoped packages).
^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$MongoDB ObjectID
Validates MongoDB ObjectID (24 hex characters).
^[a-f0-9]{24}$SQL Table Name
Validates SQL table/column names (starts with letter or underscore).
^[a-zA-Z_][a-zA-Z0-9_]*$Redis Key Pattern
Common Redis key naming pattern.
^[a-zA-Z0-9_:.-]+$AWS S3 Bucket Name
Validates AWS S3 bucket names (3-63 chars, lowercase, no consecutive dots).
^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$Git Commit Hash
Validates Git commit SHA hash (short or full format)
^[0-9a-f]{7,40}$Semantic Version (SemVer)
Validates semantic versioning strings (MAJOR.MINOR.PATCH with optional pre-release and build metadata).
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$Docker Image Tag
Validates Docker image references with optional registry, name, and tag.
^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)?[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[a-zA-Z0-9._-]+)?$Environment Variable Name
Validates POSIX-compliant environment variable names (uppercase, underscores).
^[A-Z_][A-Z0-9_]*$Hex Color Code
Validates CSS hex color codes in 3, 6, or 8-digit format (with optional alpha).
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$CSS Class Selector
Validates a CSS class selector starting with a dot.
^\.[a-zA-Z_-][a-zA-Z0-9_-]*$CSS ID Selector
Validates a CSS ID selector starting with #.
^#[a-zA-Z][a-zA-Z0-9_-]*$Terraform Resource Name
Validates Terraform resource names (lowercase, underscores, starts with letter).
^[a-z][a-z0-9_]*$CSS Custom Property (Variable)
Validates CSS custom property names (CSS variables: --primary-color).
^--[a-zA-Z][a-zA-Z0-9-]*$PostgreSQL Connection URI
Validates PostgreSQL connection strings (postgres:// or postgresql://).
^postgres(?:ql)?:\/\/(?:[^:@\/\s]+(?::[^@\/\s]*)?@)?[^:\/\s]+(?::\d+)?(?:\/[^\s?]+)?(?:\?\S*)?$MongoDB Connection URI
Validates MongoDB connection strings, including mongodb+srv.
^mongodb(?:\+srv)?:\/\/(?:[^:@\/\s]+(?::[^@\/\s]*)?@)?[^\/\s]+(?:\/[^\s?]*)?(?:\?\S*)?$Redis Connection URI
Validates Redis connection URIs (redis:// or rediss:// for TLS).
^rediss?:\/\/(?:[^:@\/\s]*(?::[^@\/\s]*)?@)?[^:\/\s]+(?::\d+)?(?:\/\d+)?$Shell Environment Variable Reference
Matches a POSIX shell variable reference: $NAME or ${NAME}.
^\$(?:[A-Z_][A-Z0-9_]*|\{[A-Z_][A-Z0-9_]*\})$Windows Environment Variable Reference
Matches a Windows-style env variable reference: %NAME%.
^%[A-Za-z_][A-Za-z0-9_]*%$PostgreSQL JDBC URL
Validates a JDBC connection URL for PostgreSQL (Spring, Hibernate, JDBC drivers).
^jdbc:postgresql:\/\/[\w.-]+(?::\d{1,5})?\/[\w-]+(?:\?[\w=&%.+-]*)?$MySQL JDBC URL
Validates a JDBC connection URL for MySQL or MariaDB.
^jdbc:mysql:\/\/[\w.-]+(?::\d{1,5})?\/[\w-]+(?:\?[\w=&%.+-]*)?$Tailwind Arbitrary Value Class
Matches a Tailwind CSS arbitrary value class like w-[42px], bg-[#1da1f2], grid-cols-[1fr_2fr].
^[a-z-]+\[(?:[^\]]+)\]$Docker Image Tag
Validates a Docker image tag (1-128 chars, alphanumeric + _ . -, cannot start with . or -).
^[\w][\w.-]{0,127}$Kubernetes Resource Name (RFC 1123)
Validates a Kubernetes resource name: lowercase RFC 1123 label, 1-63 chars, alphanumeric + hyphen.
^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$HSL Color Value
Validates a CSS HSL or HSLA color value.
^hsla?\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%(?:\s*,\s*(?:0?\.\d+|0|1))?\s*\)$React Component Name (PascalCase)
Validates a React or Vue component name (PascalCase, no underscores or dashes).
^[A-Z][A-Za-z0-9]*$Next.js Dynamic Route Segment
Matches a Next.js dynamic route segment: [id], [...slug], or [[...slug]].
^\[(?:\.\.\.)?\[?([A-Za-z_][\w-]*)\]?\]$Frequently Asked Questions
How do I validate a semantic version string?
Use the SemVer pattern. It matches MAJOR.MINOR.PATCH with optional pre-release (e.g., 1.0.0-alpha.1) and build metadata.
What's the UUID v4 regex?
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
How do I validate a hex color in CSS?
Use the Hex Color Code pattern: ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$ - covers 3, 6, and 8-digit formats.
Looking for patterns in other categories?
Browse all 300 patterns