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

Time:10-22

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!

CodePudding user response:

You can do it without regex:

select split('advice/management?sdjghwehgf', '?')[OFFSET(0)]

CodePudding user response:

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

  • Related