0

I am looking for a regular expression syntax accepted by RE2, to convert the following strings to numeric:

"339,840" -> 339840

"$100,000" -> 100000

"0.75" -> 0.75

"1" -> 1

1 Answer 1

1

Below is for BigQuery Standard SQL

You can use cast(regexp_replace(val, r'[^\d.]', '') as numeric)

See below example

#standardSQL
with `project.dataset.table` as (
  select "339,840" val union all
  select "$100,000" union all
  select "0.75" union all
  select "1" 
)
select cast(regexp_replace(val, r'[^\d.]', '') as numeric)
from `project.dataset.table`

with output

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Very elegant, Thank you!

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.