JDBC Connection URL
Match JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("jdbc:[a-z0-9]+:\\/\\/[^\\/?\\s]+(?:\\/[\\w\\-]+)?(?:\\?\\S*)?", "g");
const input = "url=jdbc:postgresql://db.internal:5432/main";
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"jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)?")
input_text = "url=jdbc:postgresql://db.internal:5432/main"
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(`jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)?`)
input := `url=jdbc:postgresql://db.internal:5432/main`
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
jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)? (flags: g)Raw source: jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)?
How it works
Examples
Input
url=jdbc:postgresql://db.internal:5432/mainMatches
jdbc:postgresql://db.internal:5432/main
Input
jdbc:mysql://localhost:3306/test?useSSL=falseMatches
jdbc:mysql://localhost:3306/test?useSSL=false
Input
no jdbc url hereNo match
—Common use cases
- •Java / JVM application config validation
- •Spring Boot properties auditing
- •Migrating between database drivers
- •Detecting committed credentials in JDBC URLs
Related patterns
Generic Connection String (URL Form)
NetworkingParse generic URL-form connection strings: `protocol://[user[:pass]@]host[:port][/database]`.
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.
MongoDB Connection URI
NetworkingMatch MongoDB connection URIs in both standard `mongodb://` and SRV `mongodb+srv://` formats.