I find this to be commonly referred to as backlinks. In R, you can use \\ 1 \\ 2, etc.
re.examples <- c( 'What_are_we_doing?', 'Woe, that a young fowl should fly the coop', '2011/12/24', 'Subject: More information, then less important stuff.' ) sub("([0-9]+)/([0-9]+)/([0-9]+)","Year is \\1 Month is \\2 Day is \\3",re.examples[3]) sub("^([A-Za-z ]+): ([A-Za-z ]+), ([A-Za-z ]+).$","\\2",re.examples[4])
I am not sure about the support of \ d in R. I generally just use [0-9] anyway, since I know that this works and it is easier for me to read.
Edit: @Andri and @Richie Cotton suggested two suggestions in the comments, which I will include here for completeness. [: digits:] works, but, in my opinion, there is little readability compared to [0-9]. \\ d also works.
source share