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"'<>]+/giHow to read it
\s matches any whitespace, including tabs and newlines.
A negated class [^ … ] matches anything except the listed characters.
g — global — keep going after the first match instead of stopping
i — ignore case
Find matches in your own text
no inputTry:
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 verifiedDocs 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 languagesJavaScript
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
4GroupExtraction
Flags/gi
Examples4
SafetyOK