2

I need to use REGEXP_EXTRACT on various URLs i have in BigQuery and extract different strings from them.

For exmaple, i have this URL:

url = https://www.whatever.com/record-a-beautiful-and-professional-voice-over?sec_context=recommendation&context_alg=nodes&sec_context_referrer=search

I want to use the BigQuery REGEXP_EXTRACT function and extract the string that comes after the parameter named context_alg= (presented after the first & in the URL). Meaning - my output will be nodes.

(context_alg is a parameter in the URL and always has the same name)

So actually I need to use something like:

REGEXP_EXTRACT(url, "REGEXP that bring back 'nodes')

Thank you !

1
  • 1
    your question is not clear enough... please clarify with proper input and exact output you want... if you cant explain better then give two set of intput and two set of output respectively Commented Oct 18, 2016 at 9:50

2 Answers 2

4

If you need to extract all parameters from a URL, you can also use REGEXP_EXTRACT_ALL as follows:

REGEXP_EXTRACT_ALL(query,r'(?:\?|&)((?:[^=]+)=(?:[^&]*))') as params

This will return the result as an array (see How to extract URL parameters as ARRAY in Google BigQuery):

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for sharing this code. just adding one thing to save some ppl's time: If you want to grab a particular parameter's value,. use this regex expression r'(?:\?|&)(?:(?:[myparameter=]+)=([^&]*))'
3

try below for BigQuery

REGEXP_EXTRACT(url, r'context_alg=([^?&#]*)')  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.