tools / regex library / url
regex pattern · ready to copy

Regex for matching URLs

Capture http(s) URLs from free text — comments, logs, markdown.

intermediate javascript / pcre / python4 use cases

The pattern

https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*

Test cases

InputResult
https://voiddo.com/toolsmatches
http://localhost:3000/api/v1matches
https://docs.example.io/path?q=1#fragmatches
ftp://noperejects
just-textrejects
google.com (no scheme)rejects

Edge cases & caveats

Greedy on trailing punctuation — strip trailing `.`, `,`, `)` after match. For domain-only matching (no scheme), drop the `https?://` prefix and leave `\w.-]+\.\w{2,}`.

Common use cases

Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab  

Related

iban · credit card number · us zip code · jwt