![](/img/trans.png)
[英]Specifying a word followed by a specific word followed by max of 3 words in regex in R
[英]Regex with a variable and not followed by anything in R
再一次,我正在为 Regex 苦苦挣扎! 我需要在带有grep
函数的 R 中找到一个表达式:
下面是一个例子:
for (j in 1:2){
aaa = c(0,-0.5)
JOP = c("one.HR0","twoHR0", "oneHR0.5", "twoHR0.5")
print(grep(paste0("HR", abs(aaa[j]),"?!."), JOP))}
在我的示例中,我想在第一个循环中获得one.HR0
、 twoHR0
等等。
但是我的正则表达式不起作用! 提前致谢 :-)
这样做,你在追求什么?
for (j in 1:2){
aaa = c(0,-0.5)
JOP = c("one.HR0","twoHR0", "oneHR0.5", "twoHR0.5")
print(grep(paste0("HR", abs(aaa[j]),"$"), JOP, value=T)) #value=T returns actual values and not only the matching indexes in JOP
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.