x <- c("[@Fotheringham1981]", "df[1,2]") gsub("\\[@([^]]*)]", "\\\\cite{\\1}", x)