Number after captured group in regex

Viewed 35

I want to write a simple RegEx to add leading zeros to my R code. Simplest way is to find (\s)\.(\d) and replace it with \10.\2. But it doesn't work in R as it apparently thinks it's 10th captured group rather than 1st followed by a literal 0. According to this question RStudio uses PCRE but no method for PCRE (or any other engine) from those described here works in RStudio find & replace feature. Is it possible to put a number after a captured group without leaving RStudio?

1 Answers

As a work-around, you can use lookarounds here:

Search for: (?<=\s)\.(?=\d)
Replace with: 0.

See the regex demo.

Related