JDBC Connection URL in JS
Match JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.
Try it in the JS tester →Pattern
regexJS
jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)? (flags: g)JavaScript / ECMAScript code
jsJavaScript
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).
How the pattern works
jdbc: matches the literal scheme prefix. [a-z0-9]+ captures the driver name (mysql, postgresql, oracle, sqlserver, h2, etc.). :\/\/ matches the separator. [^\/?\s]+ captures the host[:port]. (?:\/[\w\-]+)? optionally matches a database name. (?:\?\S*)? optionally matches query parameters.
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
—