0

I am having trouble extracting a string in my dataset using REGEXP_EXTRACT in bigquery. Below are my strings and desired outputs:

STRING: Gas Safe_160x600_v2b   DESIRED OUTPUT: 160X600
STRING: Gas Safe_60x150_v2b   DESIRED OUTPUT: 60X150
STRING: Gas Safe_100x40_v2b   DESIRED OUTPUT: 100X40

Can anyone help?

2 Answers 2

1

Below is for BigQuery Standard SQL

Few options are using SPLIT or REGEXP_EXTRACT as in below example

#standardSQL
SELECT text, 
  SPLIT(text, '_')[SAFE_OFFSET(1)] extracts1,
  REGEXP_EXTRACT(text, r'_(.*)_') extracts2
FROM `project.dataset.table`   

If to apply to sample data in your question - result is

Row text                    extracts1   extracts2    
1   Gas Safe_160x600_v2b    160x600     160x600  
2   Gas Safe_60x150_v2b     60x150      60x150   
3   Gas Safe_100x40_v2b     100x40      100x40   
Sign up to request clarification or add additional context in comments.

Comments

0

You should use this expression:

([0-9]+x[0-9]+)

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.