0

I have column with this strings:

['autre__renvoi_vers_un_mail', 'contact_type__email']
['contact_type__email', 'internal__shop', 'uk']

I need to get from the string ONLY the contact_type__* part (appears only once in each row)

contact_type__email
contact_type__email

Any suggestions?

2 Answers 2

2

You could use regexp function regexp_extract(), like:

regexp_extract(mycol, 'contact_type__[a-zA-Z0-9_]*')

This will match on string 'contact_type__ followed by a sequence of letters, numbers, or underscore (which are commonly defined as word characters).

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

1 Comment

@OksanaOk: welcome! Just to check, what if you use \\w instead of \w?
0

Given this example:

create table t (col varchar(100));
insert into t values
('[''autre__renvoi_vers_un_mail'', ''contact_type__email'']'),
('[''contact_type__email'', ''internal__shop'', ''uk'']');

You can use:

select
    substring 
    (
     col,
     charindex('contact_type', col) + 14,
     charindex('''', col, charindex('contact_type', col)) - charindex('contact_type', col) - 14
    )
from
    t;

db<>fiddle here

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.