Advertisement
Guest User

Untitled

a guest
Apr 5th, 2023
113
0
5 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. import re
  2.  
  3. original = r'1234'
  4. substitution = r'\1$'
  5. myre = re.compile('34')
  6.  
  7. # ^^^ lines i cannot change
  8.  
  9. # re.error: invalid group reference 1 at position 1
  10. print(myre.sub(substitution, original))
  11.  
  12. # result: 12\1\$
  13. print(myre.sub(re.escape(substitution), original))
  14.  
  15. # desired result: 12\1$
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement