This is pretty basic, but I can't seem to find how to return the already-matched expression in regexes in R.

For example, suppose I wanted to add a period after an initial, for example in changing `"Joe J Smith"` to `"Joe J. Smith"`.

My approach is to use `gsub("(?<=\\s|^)[A-Z](?=\\S|$)","\\1.",string,perl=T)`. (I'm no expert on regex, but I thought `\\1` or `$1` would return the matched expression, i.e. `"J"` for the string given.

For nought, though, as this returns: `"Joe . Smith"`

I'm sure this is simple, but I can't find any examples trying to do something similar in R, which has its own brand of base regex.