Spreadsheet formula to extract regex groups

Viewed 35

I'm trying to turn this R_A_E_M_YT_Keywords_A_47 into this R_A_E_Keywords

What is missing in my spreadsheet formula?

=REGEXREPLACE(Input!I28:I,"([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)", "$1_$2_$3_$6")
2 Answers

_47 leaves there because you haven't replaced it.

=REGEXREPLACE(Input!I28:I,"([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+)_([A-Za-z]+).*$", "$1_$2_$3_$6")

A different approach:

=join("_", query(split(A2, "_"), "Select Col1, Col2, Col3, Col6", 0))

enter image description here

Related