How to Extract All URLs from Text or HTML (Online, Sheets, Excel, Command Line)
· 5 minutes read

Collecting links by hand is tedious: you copy one, scroll, copy the next, and still miss a few. Whether you are auditing the outbound links of a page, gathering sources from a long document or cleaning up a chat export, it is much faster to extract all URLs from the text automatically.
The tricky part is not finding https:// – it is getting a clean result: no full stop from the end of a sentence, no closing bracket from a Markdown link, no & from HTML, and no ten copies of the same address with different tracking parameters.
The fastest way: a bulk URL extractor
- Open the URL extractor.
- Paste your text. It can be plain text, Markdown or the HTML source of a page.
- The links appear on the right, one per line, duplicates removed.
- Adjust the options:
- Only domains – list
blog.example.cominstead of full URLs. - Remove query strings – cut everything after
?or#, so?utm_source=…variants merge into one. - Domain contains – keep only links to a given site, e.g. your own domain for internal links.
- Find www. links – also catch addresses written without
https://. - Sort A–Z – sort the list alphabetically.
- Only domains – list
- Copy or download the list.
The extractor removes sentence punctuation from the end of each link, but keeps brackets that belong to the address – so https://en.wikipedia.org/wiki/Mercury_(planet) stays intact even inside parentheses. HTML attributes such as href and src are read too, and & is converted back to &.
How to extract all links from a web page
The easiest source is the page's HTML:
- Open the page and press Ctrl+U (Cmd+Option+U on a Mac) to view the source.
- Press Ctrl+A and Ctrl+C.
- Paste it into the URL extractor.
Only absolute links are extracted. Relative links such as /about have no domain, so they are skipped.
If you prefer the browser's developer console (F12 → Console), this one-liner copies all resolved link targets, including relative ones turned into full URLs:
copy([...new Set([...document.querySelectorAll('a[href]')].map(a => a.href))].join('\n'))
The copy() helper is available in the Chrome, Edge and Firefox consoles; the result is placed on your clipboard.
How to extract URLs in Google Sheets
For text in column A, this returns the first URL in each cell:
=IFERROR(REGEXEXTRACT(A2, "https?://[^\s""<>]+"), "")
Note the doubled quote inside the pattern – that is how a literal " is written in a Sheets formula. The formula returns only one link per cell and keeps a trailing full stop if the URL ends a sentence, so check the result or run it through the online tool.
If your cells contain hyperlinks inserted with Insert → Link (blue text with a hidden address), the address is not part of the cell text and Sheets has no built-in formula to read it. A practical workaround: File → Download → Web page (.html), open the downloaded HTML file in a text editor and paste its source into the URL extractor – the href values are picked up.
How to extract hyperlink addresses in Excel
In Microsoft 365 with regex functions you can use the same pattern as above:
=REGEXEXTRACT(A2, "https?://[^\s""<>]+")
For cells with hidden hyperlinks, Excel needs a tiny VBA function. Press Alt+F11, insert a module and paste:
Function GetURL(cell As Range) As String
If cell.Hyperlinks.Count > 0 Then GetURL = cell.Hyperlinks(1).Address
End Function
Then use =GetURL(A2) in any cell. Save the workbook as .xlsm to keep the macro.
How to extract URLs on the command line
On Linux or macOS:
grep -oE 'https?://[^[:space:]"<>]+' notes.txt | sed 's/[.,;:!?)]*$//' | sort -u
The sed step strips trailing punctuation. It also removes a closing bracket that belongs to the URL, so check Wikipedia-style links manually.
In PowerShell:
Select-String -Path .\notes.txt -Pattern 'https?://[^\s"<>]+' -AllMatches |
ForEach-Object { $_.Matches.Value } | Sort-Object -Unique
Common pitfalls
- Trailing punctuation. "See https://example.com/page." – the dot is not part of the link and will produce a 404 if you keep it.
- Brackets. Markdown links end with
), Wikipedia URLs contain(…). A good extractor only removes unbalanced closing brackets. - HTML entities. In page source a link like
?a=1&b=2really means?a=1&b=2. - Tracking parameters.
utm_source,fbclidand similar make identical pages look different. Strip query strings before deduplicating – unless the parameters matter (search pages, product variants). - Links without a scheme. People often write
www.example.com. Decide whether you want those included. - Case. Domain names are case-insensitive, paths usually are not.
https://Example.com/Aandhttps://example.com/Aare the same, but/Aand/amay not be.
FAQ
Can I get only the list of domains?
Yes, check Only domains in the URL extractor. Each domain is listed once; subdomains are kept as separate entries.
How do I extract e-mail addresses from the same text?
Use the email extractor. It works the same way – paste the text and copy the result.
How do I remove duplicate URLs from an existing list?
Paste the list into the URL extractor with Unique only on, or use the duplicate remover for any list.
Does the tool visit or check the links?
No. It only reads the text you paste, entirely in your browser. No link is opened and nothing is sent to a server.