Due to conversions between pandoc-citeproc and latex I\'d like to replace this
[@Fotheringham1981]
with this
\\cite{Fotheringham1
You need to use capturing group.
x <- c("[@Fotheringham1981]", "df[1,2]") gsub("\\[@([^\\]]*)\\]", "\\\\cite{\\1}", x, perl=T) # [1] "\\cite{Fotheringham1981}" "df[1,2]"
or
gsub("\\[@(.*?)\\]", "\\\\cite{\\1}", x) # [1] "\\cite{Fotheringham1981}" "df[1,2]"