result = re.sub('abc', '', input) # Delete pattern abc
result = re.sub('abc', 'def', input) # Replace pattern abc -> def
result = re.sub(r's+', ' ', input) # Eliminate duplicate whitespaces using wildcards
result = re.sub('abc(def)ghi', r'1', input) # Replace a string with a part of itself
re.sub(pattern,replacement,string)
re.sub finds all matches of pattern in string and replaces them
with replacement.
#Example
re.sub("[^0-9]","","abcd1234") #Returns 1234
import re
print(re.subn('ub', '~*', 'Subject has Uber booked already'))
t = re.subn('ub', '~*', 'Subject has Uber booked already',
flags=re.IGNORECASE)
print(t)
print(len(t))
# This will give same output as sub() would have
print(t[0])