Here is my situation:
re.sub(r'([^\\])', r'\1[\W\1]*', string)
It is straight forward that I want to append [\W(itself)] after (itself) for itself being a group of characters (can be special). That is why I need to put it in a set to strip away all special meanings. However, my group can be a SET. I know that nested sets do not work. How do I escape / remove the square brackets to safely put my group in the set?
My other attempt was to use \1(\W|\1)* instead, but I need to escape characters in my group without escaping possible square brackets in the group. How do I do so?
This is a dilemma. I do not know how to solve this problem and which way to go. Please help.
Thank you very much.
EDIT: I skipped a step. After matching a character but \ (the [^\] part) and replace with the explained expression, I will sometime need to replace it with a set of similar characters. So, 'a' becomes '[a@]', 's' becomes '[s5$]', etc... The question was really wrong. But I solved the problem, so if you are still trying to make some sense out of what I wrote earlier, please don't :)