0

I'm trying to extract a parameter from a field. Unfortunately, this parameter can comes in two flavors of key=value. The first uses key = "ch" (e.g. foo.com/bar?ch=facebook) and the second uses key = "cid" (e.g. foo.com/bar?cid=facebook).

I tried to extract these params using

REGEXP_EXTRACT(page_url, r'(ch|cid)=([A-Za-z]+)') as channel

However, this gives me the error

Regular expressions passed into extraction functions must not have more than 1 capturing group

which makes sense.. Is there nice solution to this problem, other than something like

case 
  when REGEXP_CONTAINS(page_url, 'ch=') then REGEXP_EXTRACT(page_url, r'ch=([A-Za-z]+)')
  when REGEXP_CONTAINS(page_url, 'cid=') then REGEXP_EXTRACT(page_url, r'cid=([A-Za-z]+)')
end as channel
Ben
  • 15,465
  • 26
  • 90
  • 157

0 Answers0