Search code examples
regexgoogle-sheetsfiltergoogle-sheets-formulagoogle-sheets-query

How to extract strings from column into a new column?


I am new to google sheets.

How do I loop over column C and extract every occurence of Dog and Mouse together with its "index" A, C, D into columns E and F?

enter image description here

The best thing I can do right now is extract the strings row by row with

=IFS($C:$C="Dog"; $B:$B;$C:$C="Mouse";$B:$B;1=1; "") and =IFS($C:$C="Dog"; $C:$C;$C:$C="Mouse";$C:$C;1=1; "")

but this leaves free spaces in the new columns:

enter image description here


Solution

  • See if this works

    =filter(B3:C, regexmatch(C3:C, "Dog|Mouse"))
    

    or, depending on your locale

    =filter(B3:C; regexmatch(C3:C; "Dog|Mouse"))
    

    Example