Text
Extract URL query parameters and UTM tags (utm_source, utm_campaign) by key
Extract the first raw value of a named query parameter from a controlled URL, excluding its fragment.
Why naive FIND("utm_source=") breaks on sub-keys and #hash anchors!
First remove the fragment, then take only the part after the first question mark. Searching the whole URL can incorrectly match text in a path or a question mark inside a parameter value.
Prefix the query with & and search for &key=. This respects parameter boundaries and avoids treating custom_utm_source as utm_source. An appended & terminates the last value.
The result is raw text: percent escapes and plus signs are not decoded. Keys match case-sensitively, duplicate keys return the first occurrence, and a bare flag without = is not treated as a valued parameter.
Use a plain nonempty key without query delimiters. This is not a complete URL parser or canonicalizer; use a standards-aware URL API for general web processing.
| Parameter Key (B2) | Boundary Matched | Extracted Value from Sample URL |
|---|---|---|
| "utm_source" | "?utm_source=" (1st param) | "google" |
| "utm_campaign" | "&utm_campaign=" (strips #faq!) | "q4_launch" |
| "utm_content" | Absent from query | "Not Found" |
Order-independent, #fragment-safe URL query parameter extractor
An existing key with an empty value returns empty text; an absent key returns Not Found. Only the query portion is searched.
=LET(clean,TEXTBEFORE(A2&"#","#"),query,IFERROR(TEXTAFTER(clean,"?"),""),IF(B2="","Enter a key",IFERROR(TEXTBEFORE(TEXTAFTER("&"&query&"&","&"&B2&"="),"&"),"Not Found")))Remove query and fragment text
This removes suffixes only. It does not normalize a URL, choose a canonical page or account for meaningful query parameters.
=TEXTBEFORE(TEXTBEFORE(A2 & "#", "#") & "?", "?")Try the example
Use the original values or change them to test your understanding.