Google-sheets – Match mixed data

google sheets

In one column there are mixed sections, which are to be matched with data from other sheet. But as the sections format is different in entire column, not able to match

I have 2 sheets in which i have

Sheet 1 :

Column A         
AB-C,DE   

Sheet 2 :

Column A    
ABCDE   

I have to match this data in both the sheets

Best Answer

So my solution isn't perfect du to my limited knowledge in regular expression combined to the messy data.

First, extract the codes from Sheet1!A:A, replacing non digits with an emoji.

REGEXREPLACE(A2,"[^\d*]","🕳️")

Then split each code to create an array

split(REGEXREPLACE(A2,"[^\d*]","🕳️"),"🕳️",true,true)

Now we need to create a regex when we'll try to matches theses codes with Sheet2

"^"&textjoin("|-",true,split(REGEXREPLACE(A2,"[^\d*]","🕳️"),"🕳️",true,true))&"-"

Now use this regex with regexmatch to find correct matches. This formula returns the row if true.

=ArayFormula(if(REGEXMATCH(Sheet2!A3:A,"^"&textjoin("|-",true,split(REGEXREPLACE(A3,"[^\d*]","🕳️"),"🕳️",true,true))&"-"),row(Sheet2!A3:A),))

Finally =textjoin to display results in one cell :

=TEXTJOIN("|",true,
   ArrayFormula(
      if(
            REGEXMATCH(Sheet2!A2:A,"^"&textjoin("|-",true,split(REGEXREPLACE(A2,"[^\d*]","🕳️"),"🕳️",true,true))&"-")
           ,row(Sheet2!A2:A),)
   )
)

Illustration :

enter image description here