Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = '(x + 2 - y)'
- '(x + 2 - y)'
- pattern = '(?P<char>[(+)])'
- repl = '\g<char>'
- >>> s = '(x + 2 - y)'
- >>> pattern = '(?P<char>[(+)])'
- >>> repl = '\g<char>'
- >>>
- >>> re.sub(pattern, repl, s)
- '\g<char>x \g<char> 2 - y\g<char>'
- >>>
- >>> repl = '\\g<char>'
- >>> re.sub(pattern, repl, s)
- '\g<char>x \g<char> 2 - y\g<char>'
- >>> repl = r'\\g<char>'
- >>> re.sub(pattern, repl, s)
- '\\g<char>x \\g<char> 2 - y\\g<char>'
- >>> repl = r'\g<char>'
- >>> re.sub(pattern, repl, s)
- '\g<char>x \g<char> 2 - y\g<char>'
- >>> repl = '\g<char>'
- >>> re.sub(pattern, repl, s)
- '\g<char>x \g<char> 2 - y\g<char>'
- >>> repl = '\1'
- >>> re.sub(pattern, repl, s)
- '\x01x \x01 2 - y\x01'
- >>> repl = '\g<1>1'
- >>> re.sub(pattern, repl, s)
- '\g<1>1x \g<1>1 2 - y\g<1>1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement