[英]Regex with a variable and not followed by anything in R
Once again, I'm struggling with Regex!再一次,我正在为 Regex 苦苦挣扎! I need to find, in R with the
grep
function, an expression:我需要在带有
grep
函数的 R 中找到一个表达式:
Below an example:下面是一个例子:
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))}
In my example, I want to get one.HR0
, twoHR0
in the first loop and so on.在我的示例中,我想在第一个循环中获得
one.HR0
、 twoHR0
等等。
But my Regex is not working!但是我的正则表达式不起作用! Thanks in advance :-)
提前致谢 :-)
Does this do, what you're after?这样做,你在追求什么?
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.