Answers for "Multiple sub in single regex"

0

Multiple sub in single regex

# Multiple sub in single regex.
import re
class Substitutable(str):
  def __new__(cls, *args, **kwargs):
    newobj = str.__new__(cls, *args, **kwargs)
    newobj.sub = lambda fro,to: Substitutable(re.sub(fro, to, newobj))
    return newobj
h = Substitutable('horse')
h = h.sub('h', 'f').sub('e','h')
print(h)
Posted by: Guest on October-19-2021

Code answers related to "Multiple sub in single regex"

Python Answers by Framework

Browse Popular Code Answers by Language