Regex will find matches that satisfy the expression but are different. How to you refer to the result instance in order to append to each instance? I have created a text file by copy/paste from a website that does not provide any sort of file download. The file I created contains a lot of text and numbers that I want to put into a spreadsheet. The numbers are of the form nn.nn and separated by spaces. Unfortunately the text also has spaces. Therefore the spaces cannot be used as a delimiter. I am using the ‘Sublime’ text editor and the regex expression I am using is ‘\d\d.\d\d’ which identifies the numbers I am after. I then want to append a comma after each nn.nn figure in order to import the text file into a spreadsheet.
The ‘Find’ tool works correctly in Sublime but the ‘Replace’ tool does just that. I want an ‘Append’ tool as there does not seem to be a way of referring to the text that has been found in the ‘Replace’ field so that I could enter ‘[what was found],’ into the ‘Replace’ box.
So, is there a way of doing this?
$n
or sed-like\n
to refer to the nth capture group. It's not clear whether there is a whole-match replacement like sed's&
. – steeldriver Feb 21 '24 at 21:18&
that I mentioned) you'd need to capture the pattern in order to use the backreference i.e.(\d\d.\d\d)
rather than plain\d\d.\d\d
- and then
in that context would be1
– steeldriver Feb 22 '24 at 13:04\1
and$1
work for me – steeldriver Feb 22 '24 at 13:11{}
button to format as code. That way, we can test our solutions and ensure that they work as you want. Note that the best way will probably be using an external tool and not Sublime itself. – terdon Feb 22 '24 at 14:14