paolotroia
paolotroia

Reputation: 43

How to extract only specific words from a string that contains delimiters in Google Sheets

I have the following string in Google Sheets:

222222*1 - preroll - MINE - Homepage - CTA - redirect

and I want to extract only specific parts of this string.

For example, I would like to extract only these

in order to create for example another string like this: 222222*1_preroll_CTA_redirect

I have already tried the Regexextract and the Split function without success. I'd like to extract only specific elements that are delimited by the dash and then concatenate them in the way I need, and possibly all at once.

Does anyone have a solution?

Thanks!

Upvotes: 0

Views: 77

Answers (2)

paolotroia
paolotroia

Reputation: 43

Thanks @doubleunary! I see that this formula extracts the elements sequentially, but I need to extract specific elements as shown in the example below:

Table with the desired output

Let me know if this is clear.

Upvotes: 0

doubleunary
doubleunary

Reputation: 18884

Use regexextract() and join(), like this:

=join( "_", regexextract(A2, "^(.+?) - (.+?) - .+? - .+? - (.+?) - (.+?)$") )

Upvotes: 1

Related Questions