I want to match two regular expressions A and B where A and B appear as ‘AB’. I want to then insert a space between A and B so that it becomes ‘A B’.
For example, if A = [0-9] and B = !+, I want to do something like the following.
match = re.sub('[0-9]!+', '[0-9] !+', input_string)
But, this obviously does not work as this will replace any matches with a string ‘[0-9] !+’.
How do I do this in regular expressions (preferably in one line)? Or does this require several tedious steps?
Use the groups!
\1and\2indicate the first and second parenthesised fragment. The prefixris used to keep the\character intact.