Python (re)

JDBC Connection URL in PY

Match JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.

Try it in the PY tester →

Pattern

regexPY
jdbc:[a-z0-9]+:\/\/[^\/?\s]+(?:\/[\w\-]+)?(?:\?\S*)?   (flags: g)

Python (re) code

pyPython
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+.

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/main

Matches

  • jdbc:postgresql://db.internal:5432/main

Input

jdbc:mysql://localhost:3306/test?useSSL=false

Matches

  • jdbc:mysql://localhost:3306/test?useSSL=false

Input

no jdbc url here

No match

Same pattern, other engines

← Back to JDBC Connection URL overview (all engines)