Daniel Zrust
Daniel Zrust

Reputation: 67

Replace String from the End of an String | REGEXP_REPLACE()

I am looking (probably) for REGEXP_REPLACE() in BigQuery to remove specific strings from the end of another string.

I need to remove ".html" and ".htm" and "/" (...plus a few more strings) from the end of the following URLs:

someurl.com/page.html
someurl.com/page.htm
someurl.com/page/
someurl.com/page/

I know I need REGEXP_REPLACE() but I'm too lame to build it.

Can someone give me a little push?

Thx!

DZ

Upvotes: 0

Views: 1114

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

Use below

select 
  url, 
  regexp_replace(url, r'(.html|.htm|/)$', '') output
from t    

If applied to sample data in your question - output is

enter image description here

Upvotes: 2

Related Questions