Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206531

Regex with a variable and not followed by anything in R

$
0
0

Once again, I'm struggling with Regex! I need to find, in R with the grep function, an expression:

  • which includes a dynamic variable (a value that changes in a loop)
  • and not followed by any character (a dot or a number).

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.

But my Regex is not working! Thanks in advance :-)


Viewing all articles
Browse latest Browse all 206531

Trending Articles