Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
i am trying to replace a named group with another one but cannot figure out how to specify the first parameter in re.sub function:

Python
reegex = re.compile("^big dog.*?(?P<groupname>big cat.*?));", re.DOTALL|re.MULTILINE)

res = re.sub(reegex, r'\g<groupname>' + "HELLO", fileData)


How can i replace only the named group part?

Regards

What I have tried:

Also tried to write it like this:
res = re.sub(r'\g<groupname>', r'\g<groupname>' + "HELLO", fileData)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900