Skip to content

Solved: How to use REGEXEXTRACT with capture groups to parse specific UTM parameters from a URL into separate columns in Google Sheets

Digital marketers and data analysts often deal with long lists of URLs containing UTM parameters (e.g., utm_source, utm_medium, utm_campaign). When these URLs are exported from tools like Google Analytics or Search Console into Google Sheets, they usually sit in a single cell.

To perform meaningful analysis—such as creating a Pivot Table to compare “Social” vs. “Email” performance—you need these parameters separated into their own columns. Manually using Data > Split text to columns is unreliable because UTM parameters don’t always appear in the same order, and URLs often contain other noisy query strings.

To extract the Source, Medium, and Campaign into three separate columns simultaneously using a single formula, use the following:

=IFERROR(REGEXEXTRACT(A2, "utm_source=([^&]+).*utm_medium=([^&]+).*utm_campaign=([^&]+)"))

Note: Replace A2 with the cell containing your URL. This formula assumes the parameters appear in that specific order. If your parameters are in varying orders, see the breakdown below for individual extraction.

The power of REGEXEXTRACT lies in capture groups—the parts of the formula wrapped in parentheses (). Each set of parentheses tells Google Sheets to “capture” that specific data and place it in a new cell to the right.

Regex Component Purpose
utm_source= Finds the literal text “utm_source=” in the string to anchor the search.
([^&]+) Capture Group 1: Matches and extracts every character until it hits an & (the end of the parameter).
.* Tells the formula to skip any characters between the first and second parameter.
utm_medium=([^&]+) Capture Group 2: Finds the medium value and extracts it into the second column.
utm_campaign=([^&]+) Capture Group 3: Finds the campaign value and extracts it into the third column.
  1. Ensure you have three empty columns to the right of your URL column.
  2. Click on the first empty cell (e.g., B2).
  3. Paste the formula: =IFERROR(REGEXEXTRACT(A2, "utm_source=([^&]+).*utm_medium=([^&]+).*utm_campaign=([^&]+)")).
  4. Drag the fill handle down to apply the formula to the rest of your list.
  1. Parameter Order Sensitivity: The “Quick Solution” formula expects Source, then Medium, then Campaign. If your URLs are inconsistent (e.g., Medium comes before Source), the formula will return an error. To fix this, use three separate formulas in three columns:
    • Source: =IFERROR(REGEXEXTRACT(A2, "utm_source=([^&]+)"))
    • Medium: =IFERROR(REGEXEXTRACT(A2, "utm_medium=([^&]+)"))
    • Campaign: =IFERROR(REGEXEXTRACT(A2, "utm_campaign=([^&]+)"))
  2. Forgetting IFERROR: If a URL is missing a UTM tag (e.g., it has a source but no campaign), REGEXEXTRACT will return a #N/A error. Always wrap your formula in IFERROR() to keep your spreadsheet clean.
  3. Overwriting Data: Because REGEXEXTRACT with multiple capture groups “spills” into adjacent cells, ensure those cells are empty. If you have text in C2 and the formula in B2 tries to output data there, you will get a #REF! error.