How to perform this javascript regex into Python (3.2)?
exmple_string.replace(/-/g, '.').replace(/(^|\.)([0-9]+)($|\.)/g, '[$2]$3');
The regex should work as following:
How to replace and correct json path string with regex?
I tried the re library, but don't know how to peform the periods [$2]$3
re.sub? It should be pretty straight-forward. . .u = pattern.replace('-', '.')v = re.sub(r'(^|\.)([0-9]+)($|\.)', r'[$2]$3', u)but got no success, the periods do not workr[\2]\3.