View Single Post
Old 11-19-2022, 08:07 PM   #1
Deina97
Member
Deina97 began at the beginning.
 
Deina97's Avatar
 
Posts: 17
Karma: 10
Join Date: Nov 2014
Device: Samsung Note
Regex replacement group before digit

I'm a bit anal. I like to have all my css rules zero filled, so instead of "calibre1", I like "calibre01". And I know just enough Regex to be dangerous.

When I was just doing the rules starting with "calibre" all was fine, I simply used
Code:
Find:
   calibre([1-9])(\D)

Replace:
   calibre0\1\2
and all was copacetic.

Then I decided to get fancy and additionally find "MsoNormal", so that gave me

Code:
Find:
   (calibre|MsoNormal)([1-9])(\D)
which worked a treat to find what I wanted. The problem came with the replace.

I tried using:
Code:
Replace:
   \10\2\3
That gave me a "IndexError: no such group", because it thought I wanted to insert group \10, instead of \1.

I tried putting a space in "\1 0", but that didn't work because it put a space in my output.

How do I solve this, please?
Deina97 is offline   Reply With Quote