英文:
How do I check if every word in a cell is in another cell, regardless of word order?
问题
搜索词 | 待搜索内容 | 匹配? |
---|---|---|
Apple Bicycle | Bicycle Tree Apple | 匹配 |
Cat Train | Train Boy Banana | 不匹配 |
英文:
If you have a cell with a text string in it, and want to check if every word in that string is contained in another cell, regardless of word order, how would you go about doing that?
Example:
Search Terms | To Be Searched | Match? |
---|---|---|
Apple Bicycle | Bicycle Tree Apple | Match |
Cat Train | Train Boy Banana | No Match |
答案1
得分: 2
If you have Microsoft-365 then could try-
=IF(AND(ISNUMBER(SEARCH(TEXTSPLIT(A2,," "),B2))),"Match","No Match")
英文:
If you have Microsoft-365 then could try-
=IF(AND(ISNUMBER(SEARCH(TEXTSPLIT(A2,," "),B2))),"Match","No Match")
答案2
得分: 1
为了检查一个单元格中的每个单词是否出现在另一个单元格中,无论单词顺序如何,可以使用以下公式:
=IF(PRODUCT(ISNUMBER(SEARCH(TEXTSPLIT([@Cell1]," "),[@Cell2]))+0),"匹配","不匹配")
上述公式假设Cell1包含你想要搜索的所有单词,这些单词由空格分隔,Cell2是你将要搜索的单元格。如果单词由其他字符分隔,比如逗号,TEXTSPLIT 部分会像这样:
TEXTSPLIT([@Cell1],",")
该公式的工作原理如下:
- 使用分隔符拆分字符串 - 使用TEXTSPLIT
- 在另一个单元格中搜索每个部分 - 使用SEARCH
- 检查是否返回数字 - 使用ISNUMBER(SEARCH返回位置数字)
- 添加零以将true/false转换为1/0
- 将结果相乘,只有当所有术语都被找到时才得到1 - 使用PRODUCT
- 使用IF语句返回"匹配"如果为true(1),或"不匹配"如果为false(0)
重要提示: 这会匹配包含在其他单词中的单词。例如,如果Cell1包含"苹果 自行车",Cell2包含"自行车 树 菠萝",这将返回"匹配"。(参考 Jos Woolley)
要忽略包含在其他单词中的单词,可以使用以下公式:
=IF(AND(ISNUMBER(XMATCH(TEXTSPLIT(A2," "),TEXTSPLIT(B2," ")))),"匹配","不匹配")
(参考 harun24hr)
英文:
To check if every word in a cell appears in another cell, regardless of word order, use the following formula:
<code>=IF(PRODUCT(ISNUMBER(SEARCH(TEXTSPLIT([@Cell1]," "),[@Cell2]))+0),"MATCH","NO MATCH")</code>
The above formula assumes Cell1 has all the words you want to search for, the words are separated by a space, and Cell2 is where you'll be searching. If the words are separated by something else, like a comma, the TEXTSPLIT portion would look like this instead:
<code>TEXTSPLIT([@Cell1],",")</code>
The formula works by:
- Splitting the string by a delimiter - with TEXTSPLIT
- Searching for each portion in the other cell - with SEARCH
- Checking if this returns a number - with ISNUMBER (SEARCH returns a position number)
- Adding zero to turn true/false into 1/0
- Multiplying the results to only get a 1 if all terms are found - with PRODUCT
- Returning "MATCH" if true (1) or "NO MATCH" if false (0) using an IF statement
IMPORTANT: This will match if words are contained within other words. For instance, if Cell1 contains "Apple Bicycle" and Cell2 contains "Bicycle Tree Pineapple", this will return "MATCH". (Per Jos Woolley)
To ignore words contained within other words, you can use the following:
<code>=IF(AND(ISNUMBER(XMATCH(TEXTSPLIT(A2," "),TEXTSPLIT(B2," ")))),"MATCH","NO MATCH")</code> (Per harun24hr)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论