Multiple REGEXEXTRACT in Google Sheets formula

Assuming there are spaces between the different tags (as in your example) you can try in B2

=textjoin(", ", 1, ArrayFormula(iferror(regexextract(split(regexreplace(A2, "\](\s)\[","]_["), "_"), "\[brand\](.*?)\[brand\]"))))

If not, and the number of brands is fixed (eg. 2 brands) you can try

=regexextract(A2, rept(".*\[brand\](.*?)\[brand\]", 2))

If the number of brands present in the string is variable, you can calculate the number of brands present and use that as the second parameter in the rept() function.

=regexextract(A2, rept(".*\[brand\](.*?)\[brand\]", (len(A2)-len(substitute(A2, "[brand]",)))/(2*LEN("[brand]"))))

If you need the output to be in a single cell (as in the first formula) you can wrap join(“, “, …) around the last two formulas.

Hope that helps?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top