This is sort of a follow-up to Python regex - Replace single quotes and brackets thread.
The task:
Sample input strings:
RSQ(nam
You can use re.findall() and a simple string formatting:
re.findall()
>>> s = "SMT(name['BAKD DK'], name['A DKJ'], name['S QRT'])" >>> >>> 'XYZ({})'.format(','.join(re.findall(r"'([^']+)'", s))) 'XYZ(BAKD DK,A DKJ,S QRT)'