I’m trying to understand more about regular expressions (working though some tutorials) in R and have come across something I can’t get to work. I’m trying to grab spans of things between 2 characters (including those characters and replace them). Could someone help me to get the desired behavior out of these regexes?
d <- c("xtfo_oin5h;lx", "6b_arin;7", "xin;7")
gsub("t.+?l", "HERE", b)
gsub("_.+?\\;", "HERE", b)
Desired outcomes for these two statements:
[1] "xHEREx" "6b_arin;7" "xin;7"
[1] "xtfoHERElx" "6bHERE7" "xin;7"
It seems like this is just a minor problem of transposition, in this case, mistaking a
bfor ad. 😉work as expected!