Search code examples
excelgoogle-sheetsfiltergoogle-sheets-formula

How to filter String data using search list in Google sheets/Excel?


I want to filter addresses (column A) if they contain any city name from city list (column B). Here is how data looks like:

Adresses (Col A) Cities (Col B)
900 Rancho Diego Pkwy, Buellton, CA 92028 Ventura
3850, Toepperwein Rd, Antonio, TX 78264 San Antonio
3250 El Camino Real, Atascadero, CA 93444 Buellton
2340 Palma Dr, Ventura, CA 93090 New York
Valley Rd, Santa Maria, CA 93420

In the above table, only 2 cities (Ventura, Buellton) in column B are found in Addresses in Column A, so the output should be:

900 Rancho Diego Pkwy, Buellton, CA 92019

2340 Palma Dr, Ventura, CA 93003

I tried following formulas but to no effect:

=FILTER(A2:A, REGEXMATCH(A2:A, B2:B))
=FILTER(A2:A, MATCH(A2:A, B2:B,0))
=FILTER(A2:A, COUNTIF(B2:B, A2:A))

How to compile list of addresses (Col A) if any city name (Col B) is found in the address? Any help would be much appreciated.


Solution

  • withing GSheets please try:

    UPDATED FORMULA:

    • this strictly extracts the cities names within the address to tally against the list in Column B to avoid random mismatches.

    =FILTER(A2:A,REGEXMATCH(BYROW(A2:A,LAMBDA(ax,IF(ax="",,IFNA(IFNA(REGEXEXTRACT(ax,", ([^,]*), [A-Z]{2}"),REGEXEXTRACT(ax,", ([^,]*), [^,]*$")))))),"(?i)"&TEXTJOIN("|",1,B2:B)))