Markdown Link Extraction: View All Links in a Table

PublishedToolMarkdown Link Extractor

Contents
  1. In a link-heavy document, counting by eye is what gets it wrong
  2. How to read Markdown link syntax and extract it directly
  3. Common mix-ups and cases this approach misses
  4. Recap
  5. FAQ

Pulling only the [text](URL) links out of a Markdown post or README comes down to one problem: finding bracket and parenthesis pairs with a regular expression. Links and images (![alt text](URL)) differ only by a single exclamation mark in front, so once a document gets long, it's easy to miss them just by scanning.

This post shows how that parsing works, and then covers the cases it misses, like reference-style links or URLs that contain parentheses.

Summary ① Markdown links [text](URL) and images ![alt text](URL) differ only by the leading exclamation mark (!). ② Reference-style links ([text][ref]) or URLs with parentheses inside them may not come out correctly with simple regex matching. ③ Results come in three formats — table, URL list, and JSON — and each one covers a different amount of information.

Say you need to pull just the URLs into a list so you can translate or review a README or blog draft with several references attached.

Hyperlinks in the form [description text](url) and image links in the form ![alt text](url) look nearly identical, so when you scroll and move them over by hand, you end up mistaking an image link for a hyperlink or the other way around.

If a document has ten or so links, counting by hand won't be far off. But with dozens to hundreds mixed together, it's a different story. If you don't mark which links you've already moved, you get duplicates and gaps, and it's common for one short link tucked between paragraphs to get dropped entirely.

Inline Markdown link syntax looks like [link text](destination URL), and image syntax is the same thing with an exclamation mark in front: ![alt text](destination URL). To find these directly in text, match one pair of square brackets and the pair of parentheses right after it with a regular expression.

Written as a pattern, that's (!)?\[([^\]]+)\]\(([^)]+)\). The leading (!)? is the exclamation mark that tells you whether it's an image, \[([^\]]+)\] captures the link text inside the square brackets, and \(([^)]+)\) captures the URL inside the parentheses.

Trying it on a real document with grep

If you want to do it yourself in the terminal, grep is enough.

grep -oE '!?\[[^]]+\]\([^)]+\)' README.md

Run that command and every link and image match in the file prints on its own line. If a result line starts with an exclamation mark, it's an image; otherwise it's a hyperlink. You can also turn on regex mode in your text editor's find box and paste the same pattern to highlight every match.

Move those matches into a table or list by hand and you get the result you want. The principle is the same one the tool below handles internally. But when a single document has dozens to hundreds of matches, moving each one over takes real time.

Check it with our tool.

Markdown Link Extractor

Paste your text and it converts to a table, URL list, and JSON right away. Everything runs in your browser, with no install or sign-up.

Common mix-ups and cases this approach misses

There are three output formats, and each one carries a different scope of information.

FormatWhat it showsBest for
TableAnchor text + clickable URLChecking link text and address together
URL listPlain URLs only, one per lineCopying just the addresses to paste somewhere else
JSONArray of {text, url, isImage} objectsDropping it straight into another script or program

The most common miss is reference-style links. Syntax like [text][ref], where two square-bracket pairs sit back to back with no parentheses, doesn't match the [text](URL) pattern because the structure itself is different.

That syntax also needs you to find the definition line elsewhere in the document, in the form [ref]: URL, and connect the two — a separate job that requires a different regex.

URLs with parentheses inside them are easy to miss as well. If an address has parentheses in the middle, like (disambiguation) in a wiki article URL, the regex stops at the first closing parenthesis and the URL gets cut off partway through.

The image option and how far URL checking goes

If image links don't show up in the results, it's almost always an option issue. The "Include images" checkbox defaults to off (false), so unless you turn it on, ![alt text](URL) matches are left out of the statistics and the result list.

Also, extracted URLs only get trimmed — they aren't validated in any other way — so addresses with typos or relative paths still show up in the results as-is.

Recap

  • Markdown links and images are told apart by a single leading exclamation mark (!).
  • Only inline links in the [text](URL) form are extracted accurately; reference-style links aren't covered.
  • If a URL contains parentheses, it can get cut off at the first closing parenthesis.
  • The "Include images" checkbox is off by default, so image links are missing from the results unless you turn it on.
  • Results come in three formats — table, URL list, and JSON — so pick whichever fits what you're doing.
Markdown Link Extractor

Paste your text and it converts to a table, URL list, and JSON right away. Everything runs in your browser, with no install or sign-up.

FAQ

No. This tool focuses on inline Markdown links in the [text](URL) form and images in the ![alt text](URL) form. Reference-style links are a separate syntax with back-to-back square brackets and no parentheses, so they don't match the pattern.

Because the "Include images" checkbox described above is off. Turn it on and image matches in the ![alt text](URL) form get added to the result list, and only then does an "Image links" item appear in the statistics area at the top.

Can I click a URL in the results to open it?

Yes, in the table format. The URLs listed in the table appear as clickable hyperlinks, so you can open them in a new window and check that they're still live.

What values do I get when I output JSON?

You get an array of {text, url, isImage} objects, one per extracted link. text is the text inside the square brackets, url is the address inside the parentheses (trimmed only, with no other validation), and isImage says whether it's an image link with an exclamation mark.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. URL Link Converter: Turn Raw Text URLs Into Clickable LinksLearn the regex that finds http and https URLs in text and wraps them in a tags, plus how target=_blank, rel, truncation, and class affect the HTML.
  2. File Checksum Comparison: Verify Integrity with HashesCompare a downloaded file's hash with the official checksum to confirm it matches, and see why one changed character changes the whole value.
  3. font-display swap vs block: timeline and comparison tableCompare font-display auto, block, swap, fallback, and optional in a table: block and swap periods, timeline, and where FOUT and FOIT happen.
  4. @font-face CSS: woff2, woff, ttf src order and syntaxLearn how to write @font-face rules: why src goes woff2, woff, ttf, when font-family needs quotes, and how font-display: swap works.
  5. Check My Latitude and Longitude, Including Accuracy RadiusSee how the browser Geolocation API estimates your position from GPS, Wi-Fi, and cell signals, and what the accuracy, altitude, and speed values mean.
  6. How to Read a Hex Dump: Offsets, Hex Bytes, and ASCIILearn what the three hex dump columns mean — offset, hex bytes, and ASCII — why the offset looks different in hex or decimal, and why dots appear.

Related tools