Regex Library
Regex Library

22 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

CI/CD pipeline validationConfig file parsingCode lintingBuild scripts

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+|\*) ?){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-]*$

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 209 patterns