Home > Mobile >  How to delete information between [ ] and keep any text after it
How to delete information between [ ] and keep any text after it

Time:11-05

If I have text such as: [12 Dec 2012 20:12:12 GMT] The Weather was amazing in Cyprus.

Using Google BigQuery I would like to keep "The Weather was amazing in Cyprus." but remove the bracket how can I do this.

I am new to this.

I tried REGEXP_EXTRACT but struggling. PLEASE HELP Thank you

CodePudding user response:

Try the below utilizing the REGEXP_REPLACE function:

with sample_data as (
    select '[12 Dec 2012 20:12:12 GMT] The Weather was amazing in Cyprus.' as test_string
)
select test_string 
    , regexp_replace(test_string , r'\[. ]\s', '') as result
from sample_data

CodePudding user response:

You can also this using REGEX_EXTRACT approach. See query below where the regex (. ) enclosed in parenthesis 'r^\[. \](. )' represents any value after the brackets will be extracted:

with sample_data as (
    select '[12 Dec 2012 20:12:12 GMT] The Weather was amazing in Cyprus.' as test_string
)
select test_string 
    , regexp_extract(test_string, r'^\[. \](. )') as result_extract
from sample_data

Output:

enter image description here

  • Related