SHARE
TWEET

Untitled

a guest Jul 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. s = '(x + 2 - y)'
  2.      
  3. '(x + 2 - y)'
  4.      
  5. pattern = '(?P<char>[(+)])'
  6. repl = '\g<char>'
  7.  
  8. >>> s = '(x + 2 - y)'
  9. >>> pattern = '(?P<char>[(+)])'
  10. >>> repl = '\g<char>'
  11. >>>
  12. >>> re.sub(pattern, repl, s)
  13. '\g<char>x \g<char> 2 - y\g<char>'
  14. >>>
  15.      
  16. >>> repl = '\\g<char>'
  17. >>> re.sub(pattern, repl, s)
  18. '\g<char>x \g<char> 2 - y\g<char>'
  19.  
  20. >>> repl = r'\\g<char>'
  21. >>> re.sub(pattern, repl, s)
  22. '\\g<char>x \\g<char> 2 - y\\g<char>'
  23.  
  24. >>> repl = r'\g<char>'
  25. >>> re.sub(pattern, repl, s)
  26. '\g<char>x \g<char> 2 - y\g<char>'
  27.  
  28. >>> repl = '\g<char>'
  29. >>> re.sub(pattern, repl, s)
  30. '\g<char>x \g<char> 2 - y\g<char>'
  31.  
  32. >>> repl = '\1'
  33. >>> re.sub(pattern, repl, s)
  34. '\x01x \x01 2 - y\x01'
  35.  
  36. >>> repl = '\g<1>1'
  37. >>> re.sub(pattern, repl, s)
  38. '\g<1>1x \g<1>1 2 - y\g<1>1'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top