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

Time:01-27

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

  • 222222*1
  • preroll
  • CTA
  • redirect

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!

CodePudding user response:

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

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

CodePudding user response:

Thanks doubleunary! I see that this formula extracts the elements sequentially, but I need to extracts specific elements like the example below:

Table with the desired output

Let me know if it is clear

  • Related