在Google表格中以随机顺序搜索多个子字符串

时间:2017-05-19 16:47:57

标签: google-sheets

我遇到了一个问题,涉及匹配无序子串的集合:我认为最容易解决它:

Qualification Requirements      
Silver  B2 and R5 and Z3    
Gold    Z3 and R4 and B3    
Platinum    (B2 and R6) or (Z3 and B6)

Candidates  Codes   Qualifications
Fred    R3 Z5 Z3 B6 Platinum
Joan    Z3 R3 R4 B6 Platinum
William Z3 B2 R4 R5 Silver
Tanya   B6 R4 Z3 B3 Gold & Platinum
Sarah   B5 R4 Z3 B1 No soup for you!

这个想法是候选人名单(及相关代码)和资格要求都会随着时间而变化。我本来希望用正则表达式替换资格要求列表(我认为(?=。* B3)(?=。* Z3)或类似于“B3和Z3”的东西)然后只使用regexmatch一个vlookup或其他什么,但它需要一些正则表达式功能(lookahead)我相信Sheets正则表达式工具没有。可能有另一种方法可以做到这一点,我没有想到,所以欢迎所有的建议! 约束,如果不明显: 每个候选人的代码清单将是无序的,并且可以满足零个或多个资格要求。如果资格要求有些可读,那么它们必须具有和/或分组能力。至少,这是我的愿望清单。

谢谢!

1 个答案:

答案 0 :(得分:0)

这不是最优雅的解决方案,但它确实有效。 在代码右边的列中,将这个用于Gold:

= IF(AND(REGEXMATCH(B2" Z3&#34),REGEXMATCH(B2" B2&#34),REGEXMATCH(B2" R 5&#34)) "银""&#34)

在右侧的栏目中为Silver提供了这个:

= IF(AND(REGEXMATCH(B2" Z3&#34),REGEXMATCH(B2" R 4&#34),REGEXMATCH(B2" B3&#34)) "金""&#34)

在右边的栏中为白金投入了这个:

= IF(或(AND(REGEXMATCH(B2" B2&#34),REGEXMATCH(B2" R 6&#34))和(REGEXMATCH(B2" Z3& #34),REGEXMATCH(B2" B6"))),"铂""&#34)

然后在右侧的栏中将此作为总奖励:

= trim(C2&""& D2&""& E2)

向下拖动公式。您可以隐藏金牌,银牌和白金列。如果资格发生变化,应该很容易维护。

如果您想直接从资格要求中获取资格,请将上述公式替换为这些。他们假设资格要求在Sheet1中:

=IF(AND(RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$2,"and","")," "),0,1)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$2,"and","")," "),0,2)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$2,"and","")," "),0,3))),"Silver","")   

=IF(AND(RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$3,"and","")," "),0,1)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$3,"and","")," "),0,2)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$3,"and","")," "),0,3))),"Gold","")

=IF(or(AND(RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$4,"[()]*[or]*[and]*","")," "),0,1)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$4,"[()]*[or]*[and]*","")," "),0,2))),AND(RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$4,"[()]*[or]*[and]*","")," "),0,3)),RegExMatch($B2,index(split(REGEXREPLACE(Sheet1!$B$4,"[()]*[or]*[and]*","")," "),0,4)))),"Platinum","")