I am trying to convert a String into proper JSON notation. This string, got some correct indexes (with [idx]), and some incorrect indexes (with dot notation .idx. with these last ones starting by 1, instead of by 0). Is there anyway to "handle" captured groups using python re library or similar?
This is what I have:
import re
a = "a.[0].b.1.c"
re.sub(r'\.(\d)\.', r'.[\1].', a) # Which provides: 'a.[0].b.[1].c'
I would like it to give me 'a.[0].b.[0].c', but I do not know how can I perform operations on the captured group $1. Is it possible?
.1.with.0.?