【发布时间】:2019-02-25 10:03:22
【问题描述】:
目标: 至少一次返回带有“TAX”和“GAP”的元素,而不关心它们在字符串中的位置。
#STRING
K <- c("TAX","TAX GAP","GAP TAX","GAP of TAX","GAP") # 1st , 5th should be FALSE
#Solution
K[grepl("TAX",K) & grepl("GAP",K)]
# WRONG apporach
grepl("TAX|GAP",K) --> Only one side
grepl("TAX+GAP+",K) --> The positions are fixed , impossible to write all the possibilities
我可以用正则表达式在一行中编写多个 grepl() 语句吗?
欢迎使用其他方法
【问题讨论】: