AI Content Creation

Extract a URL From Text in Google Sheets

The regex answer almost works. It returns a link with a comma stuck on the end, which is the same as returning nothing.

By FITS TeamAugust 3, 20263 min read

You have a column of pasted notes, email bodies, or scraped snippets. Each cell has a link somewhere inside it and you want that link in its own column.

Two different problems hide under this one question, and most guides only answer the easier one.

The Old Way (REGEXEXTRACT)

Every result you find gives you this pattern.

=REGEXEXTRACT(A2, "https?://[^\s]+")

It reads as match everything after the protocol until a space. Now try it on a sentence a human actually wrote.

Check docs (https://example.com/api?v=1&ref=abc), or email support.

The formula returns https://example.com/api?v=1&ref=abc), with the closing bracket and comma attached. Paste that into a browser or feed it to IMPORTDATA and it fails. The cell looks correct at a glance, which is what makes this one expensive.

Trailing punctuation is not fixable by tightening the pattern either. A closing bracket is a legal URL character, so the regex cannot tell a bracket in the path from a bracket that closes the sentence.

The second problem is worse. If the cell shows the word Website and the link was attached with Ctrl+K, the formula returns #N/A.

That is not a pattern bug. Cell formulas only see the visible text value, never the rich text metadata underneath. Unless the link came from a =HYPERLINK() formula, no native formula can reach it. That job needs Apps Script and getRichTextValue().getRuns(). Most top-ranking pages conflate these two cases and leave you debugging a pattern that was never the problem.

The FITS Way (Ask for the Link)

For links that live in the visible text, FITS handles the punctuation problem because it reads the sentence rather than scanning characters.

=FITS("Extract the URL from this text. Return the URL only, with no trailing punctuation. Return blank if there is no URL: " & A2)

The bracket and comma are sentence punctuation, so they do not come back. The query string does, because it is part of the address.

Cells often hold several links. Say which one you want.

=FITS("This text may contain several links. Return only the first one that is not a social media profile: " & A2)

Bare domains with no protocol are the other common miss, since the regex requires http to match at all.

=FITS("Return any web address in this text, including bare domains written without http. Add https:// if the protocol is missing: " & A2)

And you can strip it down in the same pass instead of nesting a second formula.

=FITS("Extract the URL from this text and return it without query parameters or tracking tags: " & A2)

One caveat worth being straight about. If the URL is hidden behind Ctrl+K rich text, no formula can see it, including this one. Convert those cells to =HYPERLINK() or pull them with Apps Script first.

When to Use Each

If your cells contain nothing but a bare URL, REGEXEXTRACT is fine and costs nothing. Reach for =FITS() when links sit inside sentences, when punctuation surrounds them, or when a cell holds more than one. Related jobs work the same way: extracting the domain once you have the URL, pulling data from a website into Sheets, and extracting an email address from messy text. The full tour is in automating Google Sheets tasks you used to need regex for.

Get Links That Actually Open

FITS puts plain-English AI formulas inside Google Sheets. Describe the link you want and get it clean, without the trailing comma. Free tier included.