Match HTTP and HTTPS URLs using regex. Includes protocol, domain, path, and query string matching with ready-to-use patterns.
/https?://[\\w\\-._~:/?#\\[\\]@!$&'()*+,;=%]+/g| Token | Meaning |
|---|---|
http | Literal "http" string |
s? | Optional "s" for HTTPS |
:// | Literal "://" separator |
[\\w\\-._~:/?#\\[\\]@!$&'()*+,;=%]+ | One or more valid URL characters including path, query, and fragment |
https://example.comMatchhttp://test.org/path?q=1Matchhttps://sub.domain.co.uk/page#sectionMatchftp://files.example.comNo matchnot-a-urlNo match://missing-protocol.comNo matchconst urlRegex = /https?:\/\/[\w\-._~:/?#[\]@!$&'()*+,;=%]+/g;
const text = "Visit https://example.com/path?q=1 or http://test.org";
const matches = text.match(urlRegex);
console.log(matches); // ["https://example.com/path?q=1", "http://test.org"]import re
url_regex = r"https?://[\w\-._~:/?#\[\]@!$&'()*+,;=%]+"
text = "Visit https://example.com/path?q=1 or http://test.org"
matches = re.findall(url_regex, text)
print(matches) # ['https://example.com/path?q=1', 'http://test.org']Want to test this pattern with your own data?
Try this pattern in Regex Tester →