Networkingflags: g
PostgreSQL DSN
Match PostgreSQL DSN connection strings (`postgres://` or `postgresql://`), capturing the standard URL components.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
postgres(?:ql)?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\w+))?(?:\?\S*)? (flags: g)Raw source: postgres(?:ql)?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\w+))?(?:\?\S*)?
How it works
postgres(?:ql)? matches both the short and long scheme spellings. The optional auth group, host, port, and database name follow the standard URL form. (?:\?\S*)? optionally matches query parameters (sslmode, application_name, pool_max_conns, etc.).
Examples
Input
DATABASE_URL=postgresql://app:s3cret@db.neon.tech:5432/main?sslmode=requireMatches
postgresql://app:s3cret@db.neon.tech:5432/main?sslmode=require
Input
postgres://localhost/devMatches
postgres://localhost/dev
Input
no dsn hereNo match
—Common use cases
- •Linting .env files for committed credentials
- •Migration tooling that splits DSNs into parts
- •Multi-tenant routing by database name
- •Observability tags from connection metadata