Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard SQL: How to Extract Everything Before a Certain Character - Google BigQuery

I have a database with a Landing Page column with different URLs from a website like you can see in the image below:

Text

I want to keep the text from the beginning of the URL to the quotation mark before the non sense code at the end. How can I do this? Not sure if I can use Regex on SQL or how to do it.

P.S.: I am working with Google BigQuery and standard SQL.

Thanks!

like image 972
MatmataHi Avatar asked Oct 23 '25 07:10

MatmataHi


2 Answers

You can do it without regex:

select split('advice/management?sdjghwehgf', '?')[OFFSET(0)]
like image 170
Sergey Geron Avatar answered Oct 24 '25 22:10

Sergey Geron


Consider below approach

select Landing_Page, regexp_extract(Landing_Page, r'^[^?]*')
from your_table           

if applied to sample data in your question - output is

enter image description here

like image 45
Mikhail Berlyant Avatar answered Oct 24 '25 21:10

Mikhail Berlyant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!