Networkingflags: g
Generic Connection String (URL Form)
Parse generic URL-form connection strings: `protocol://[user[:pass]@]host[:port][/database]`.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
([a-zA-Z][\w+\-.]*):\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/([^?\s]*))? (flags: g)Raw source: ([a-zA-Z][\w+\-.]*):\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/([^?\s]*))?
How it works
Group 1 captures the scheme (postgres, mysql, redis, mongodb, kafka, etc.). The optional auth section captures user and optional password. Group 4 is the host. Optional port and path captures follow. This is a working starting point for parsing many SaaS connection strings; for production use a real URL parser.
Examples
Input
postgres://admin:s3cret@db.example.com:5432/mainMatches
postgres://admin:s3cret@db.example.com:5432/main
Input
kafka://broker.internal:9092Matches
kafka://broker.internal:9092
Input
no connection hereNo match
—Common use cases
- •Config file linting and secret detection
- •Migration scripts that re-write connection details
- •Observability — surfacing target hosts from logs
- •Feature gating by environment (parse host suffix)
Related patterns
JDBC Connection URL
NetworkingMatch JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.
Redis Connection URL
NetworkingMatch Redis connection URLs in both `redis://` and `rediss://` (TLS) forms, capturing user, password, host, port, and DB index.
FTP URL
NetworkingMatch FTP and FTPS URLs, capturing optional credentials, host, port, and path.
TCP/UDP Port Number
NetworkingMatch port numbers (1–65535) following a colon, as you'd find in host:port strings.