0

I am new to regex. I am trying to extract the website name from the long URL like below.

http://connect.themediatrust.com/d/?a=19481782541

I am trying to get everything before ".com" part.

SELECT
  customer_id,
  COALESCE(REGEXP_EXTRACT(referrer_uri, r'([^(.+?)".com"])'),referrer_uri) AS referrer_uri
FROM
  [zz_marketing_analytics.visit_from_zumobi]
WHERE
  referrer_uri="http://connect.themediatrust.com/d/?a=19481782541";

I am getting only "h" as refer URI. I'm not sure what's wrong.

1

1 Answer 1

3

I am trying to get everything before ".com" part.

Try below to start with

SELECT 
  REGEXP_EXTRACT(referrer_uri, r'(.*).com') AS referrer_uri,
  DOMAIN(referrer_uri), 
  HOST(referrer_uri)
FROM (SELECT "http://connect.themediatrust.com/d/?a=19481782541" AS referrer_uri)
Sign up to request clarification or add additional context in comments.

1 Comment

Did not realize there is a host function; very helpful :)

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.