I have a string, in which I'd like to substitute each [ by [[] and ] by []] (at the same time). I thought about doing it with re.sub:
re.sub(r'(\[|\])', '[\1]', 'asdfas[adsfasd]')
Out: 'asdfas[\x01]adsfasd[\x01]'
But I'm not getting the desired result -- how do I make the re.sub consider \1 in the pattern as the first matched special group?