FormulaCraft

How to extract hashtags from a text string in Excel and Google Sheets

Topic:Text manipulation

Heads up: Excel and Google Sheets do this differently.

Excel
=IFERROR(FILTER(TEXTSPLIT(TRIM(A2), " "), LEFT(TEXTSPLIT(TRIM(A2), " "), 1) = "#"), "No hashtags")
Google Sheets
=IFERROR(REGEXEXTRACT(A2, "(#\w+)"), "No hashtags")

Verified example

Computed by a real spreadsheet engine on the sample data below.

Post Text
Loving this weather! #sunshine #summer
Just shipped a new feature #buildinpublic #saas
Monday mood #coffee #mondaymotivation
No hashtags here, just a regular post

=IFERROR(FILTER(TEXTSPLIT(TRIM(A2), " "), LEFT(TEXTSPLIT(TRIM(A2), " "), 1) = "#"), "No hashtags")No hashtags

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1In Google Sheets, enter =IFERROR(REGEXEXTRACT(A2, "(#\w+)"), "No hashtags") in B2 to extract the first hashtag from the text in A2.
  2. 2To extract ALL hashtags in Sheets, use =SPLIT(REGEXREPLACE(REGEXREPLACE(A2, "#\w+", CHAR(1)), "[^" & CHAR(1) & "]+", ""), CHAR(1), FALSE, TRUE) — or wrap iteratively with ARRAYFORMULA on helper rows.
  3. 3In Excel 365, enter =IFERROR(FILTER(TEXTSPLIT(TRIM(A2), " "), LEFT(TEXTSPLIT(TRIM(A2), " "), 1) = "#"), "No hashtags") to split on spaces and keep only tokens beginning with #.
  4. 4The Excel formula TEXTSPLIT returns an array of words; LEFT(..., 1) = "#" produces a TRUE/FALSE array that FILTER uses to keep only hashtag tokens.
  5. 5For cleaner results, strip punctuation from the end of hashtags (e.g. trailing commas) with SUBSTITUTE or CLEAN before splitting.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

How do I count the number of hashtags in a cell?

In Sheets: =IF(REGEXMATCH(A2, "#\w+"), LEN(A2)-LEN(REGEXREPLACE(A2, "#\w+", "")), 0) — less elegant than a script, but functional. In Excel: =COUNTA(FILTER(TEXTSPLIT(TRIM(A2)," "), LEFT(TEXTSPLIT(TRIM(A2)," "),1)="#")).

Does this work on a column of posts?

Wrap the Excel formula in BYROW to apply it to A2:A10 at once. In Sheets, drag the formula down or use ARRAYFORMULA with careful construction.

More on Text manipulation

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: