How can I index group elements in re.sub?

how can I index a character in a matched group from within the re.sub match.

So I am trying to do this:

import re
string_test = ""
string_test = re.sub("^(.*?).(.*?)", "g<1>[0].g<2>", string_test)

My result should be: "". Is it possible to somehow index the g<1> group within the re.sub ? Obviously g<1>[0] doesn’t work.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.