stringr
Extracting a string between other two strings in R
You may use str_match with STR1 (.*?) STR2 (note the spaces are “meaningful”, if you want to just match anything in between STR1 and STR2 use STR1(.*?)STR2, or use STR1\\s*(.*?)\\s*STR2 to trim the value you need). If you have multiple occurrences, use str_match_all. Also, if you need to match strings that span across line breaks/newlines … Read more
gsub() in R is not replacing ‘.’ (dot)
You may need to escape the . which is a special character that means “any character” (from @Mr Flick’s comment) gsub(‘\\.’, ‘-‘, x) #[1] “2014-06-09” Or gsub(‘[.]’, ‘-‘, x) #[1] “2014-06-09” Or as @Moix mentioned in the comments, we can also use fixed=TRUE instead of escaping the characters. gsub(“.”, “-“, x, fixed = TRUE)