Regex to Extract URLs

All patterns
Extraction21 chars · /gi

Regex to Extract URLs

A pragmatic URL extractor for logs, markdown drafts, and support transcripts where you want to capture obvious HTTP and HTTPS links.

The expression

/https?:\/\/[^\s"'<>]+/gi

How to read it

\s matches any whitespace, including tabs and newlines.

A negated class [^ … ] matches anything except the listed characters.

gglobal — keep going after the first match instead of stopping

iignore case

Find matches in your own text

no input
Try:

This expression is unanchored, so it finds every occurrence anywhere in the text. Highlighted runs are what a replace call would rewrite.

Examples, checked in your browser

4/4 verified

Docs live at https://tinapps.com/list/regex

Matches.

Visit http://localhost:3000/test

Matches.

No link here

No match — this is the kind of input the pattern rejects.

ftp://legacy.example.com

No match — this is the kind of input the pattern rejects.

Use it in code

3 languages
JavaScript
const regex = /https?:\/\/[^\s"'<>]+/gi;
regex.test(input);
Python
import re
pattern = re.compile(r"https?:\/\/[^\s"'<>]+", re.IGNORECASE)
bool(pattern.search(input))
Go
re := regexp.MustCompile("(?i)https?:\\/\\/[^\\s\"'<>]+")
matched := re.MatchString(input)

Other extraction patterns

4
GroupExtraction
Flags/gi
Examples4
SafetyOK