AK91
AK91

Reputation: 731

BigQuery regex remove/replace a list of text from a string

How would I go about removing a list of text within a string? Essentially have a URL column and want to avoid grossly long regexp's and multiple nested replace functions.

Is there a way to declare a list of text such as "http", "www.", etc and have them removed from the column in one go?

Upvotes: 2

Views: 6244

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172974

You can use below simple approach

with t as (
  select 'Is there a way to declare a list of text such as "http", "www.", etc and have them removed from the column in one go?' col
)
select regexp_replace(col, r'http|www.|etc', '') cleaned_col
from t     

with output

enter image description here

Upvotes: 6

Related Questions