Redis Connection URL
Match Redis connection URLs in both `redis://` and `rediss://` (TLS) forms, capturing user, password, host, port, and DB index.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("rediss?:\\/\\/(?:([^:@\\s]+)(?::([^@\\s]*))?@)?([^:\\/\\s]+)(?::(\\d+))?(?:\\/(\\d+))?", "g");
const input = "REDIS_URL=redis://default:pass@redis.upstash.io:6379/0";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"rediss?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\d+))?")
input_text = "REDIS_URL=redis://default:pass@redis.upstash.io:6379/0"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`rediss?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\d+))?`)
input := `REDIS_URL=redis://default:pass@redis.upstash.io:6379/0`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
rediss?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\d+))? (flags: g)Raw source: rediss?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/(\d+))?
How it works
Examples
Input
REDIS_URL=redis://default:pass@redis.upstash.io:6379/0Matches
redis://default:pass@redis.upstash.io:6379/0
Input
rediss://cluster.example.com:6380Matches
rediss://cluster.example.com:6380
Input
no redis urlNo match
—Common use cases
- •Config validation in Node/Python/Go services
- •Detecting committed Redis credentials in PRs
- •Multi-tenant Redis routing
- •Migration scripts from Redis Cluster ↔ standalone
Related patterns
Generic Connection String (URL Form)
NetworkingParse generic URL-form connection strings: `protocol://[user[:pass]@]host[:port][/database]`.
JDBC Connection URL
NetworkingMatch JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.
FTP URL
NetworkingMatch FTP and FTPS URLs, capturing optional credentials, host, port, and path.
MongoDB Connection URI
NetworkingMatch MongoDB connection URIs in both standard `mongodb://` and SRV `mongodb+srv://` formats.