In [1]:
import re
In [2]:
s = 'aaa@xxx.com bbb@yyy.com ccc@zzz.com'
In [3]:
print(re.sub('[a-z]*@', 'ABC@', s))
In [4]:
print(re.sub('[a-z]*@', 'ABC@', s, 2))
In [5]:
print(re.sub('[xyz]', '1', s))
In [6]:
print(re.sub('aaa|bbb|ccc', 'ABC', s))
In [7]:
print(re.sub('([a-z]*)@', '\\1-123@', s))
In [8]:
print(re.sub('([a-z]*)@', r'\1-123@', s))
In [9]:
t = re.subn('[a-z]*@', 'ABC@', s)
print(t)
In [10]:
print(type(t))
In [11]:
print(t[0])
In [12]:
print(t[1])