I am trying to make a search pattern that consists of a (variable, defined elsewhere)string stored in an object, a constants string and a regex at the end.
Pattern should be used to identify strings stored in a vector.
This is my attempt:
VAR<-var1
pattern<-paste0(",VAR,",-asd(\d{4,6}))
So pattern, when printed should search for “var1″,”-asd” and 4-6 digits at the end.
vec<-c("var1-asd1234", "var2-asd1234", "var1-asd12345678","var1-afd123456", "var1-asd123456")
result<-regmatches(vec, regexpr(pattern,vec))
I believe there is a problem with combining this object VAR and rest of the pattern inside paste0.
This is expected outcome:
print(result)
var1-asd1234
var1-asd123456
Any help is appreciated.