0

How do I extract the id parameter below using Big Query Regexp_Extract some rows with page urls in them that look similar to : url.com/id=userIDmadeUPofletterandnumbers&em=MemberType eg url.com/id=asd1221231sf&em=studentMember

I have tried using: a. REGEXP_EXTRACT(urlValue,"id=\w+") as Idvalue but I get the error message: Invalid string literal: "id=\w+"

I am pretty close with this: REGEXP_EXTRACT(urlValue,"(id=.*&em)") however it shows me id=asd1221231sf&em and I want to exclude id= and &em at the end

1 Answer 1

3
#standardSQL
WITH `project.dataset.table` AS (
  SELECT 'url.com/id=userIDmadeUPofletterandnumbers&em=MemberType' urlValue UNION ALL
  SELECT 'url.com/id=asd1221231sf&em=studentMember'
)
SELECT REGEXP_EXTRACT(urlValue, r'id=(\w+)') id, urlValue
FROM `project.dataset.table`

Row id                              urlValue     
1   userIDmadeUPofletterandnumbers  url.com/id=userIDmadeUPofletterandnumbers&em=MemberType  
2   asd1221231sf      url.com/id=asd1221231sf&em=studentMember    
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks ! Any idea why adding that extra r at the beginning of the Regex makes it work - I can't see a link to it in the documentation
those are so called raw strings you can check them here

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.