Regex to find all URLs in text

Use /https?:\/\/[^\s<>"']+/g to find every match in a text. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

/https?:\/\/[^\s<>"']+/g
Open in Regex Tester

Sample text

Docs: https://devpack.app/regex-tester and http://example.com/path?q=1. See <a href="https://example.org/page">this</a> too.

3 matches

https://devpack.app/regex-tester http://example.com/path?q=1. https://example.org/page

How the pattern works

PartMeaning
https?http or https
:\/\/The literal ://
[^\s<>"']+Everything up to whitespace, an angle bracket or a quote

Code examples

JavaScript

const matches = text.match(/https?:\/\/[^\s<>"']+/g) ?? [];

Python

import re

matches = re.findall(r'''https?://[^\s<>"']+''', text)

PHP

preg_match_all('/https?:\/\/[^\s<>"\']+/', $text, $m);
$matches = $m[0];

Notes and limitations

Trailing punctuation such as a sentence-ending period is captured as part of the URL; trim [.,;:!?)]+$ from each match.

Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool

Frequently asked questions

What is the regex to find all URLs in text?
/https?:\/\/[^\s<>"']+/g — it finds every match in a text. See the table above for what each part does.
Does it work in Python and PHP?
Yes — the code examples above use the same pattern with re in Python and preg functions in PHP.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.