I have multiple 24-hour time strings through several files. For example, 1234, which I wish to replace with 12:34.
Finding them is easy, just \d\d\d\d, that I understand and it works. However, what replace string do I need. In other words, say xx:xx, what do I put in place of each x.
I've tried numbers of things to no avail. I'm obviously not understanding how I get it to remember the digits it found and to recall them in the replace string.
If in your example data 4 digits represent 24 hour time strings you could match 2 capturing groups between word boundaries to prevent a match with more then 4 digits. You can Adjust the word boundaries to your requirements.
Match
\b(\d{2})(\d{2})\bReplace
group1:group2
\1:\2Explanation
\bMatch a word boundary(\d{2})Capture in a group 2 digits(\d{2})Capture in a group 2 digits\bMatch a word boundaryNote
Matching 4 digits does not verify a valid 24 hour time. You could match that using for example
\b([01][0-9]|2[0-3])([0-5][0-9])\band replace with\1:\2