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))


ABC@xxx.com ABC@yyy.com ABC@zzz.com

In [4]:
print(re.sub('[a-z]*@', 'ABC@', s, 2))


ABC@xxx.com ABC@yyy.com ccc@zzz.com

In [5]:
print(re.sub('[xyz]', '1', s))


aaa@111.com bbb@111.com ccc@111.com

In [6]:
print(re.sub('aaa|bbb|ccc', 'ABC', s))


ABC@xxx.com ABC@yyy.com ABC@zzz.com

In [7]:
print(re.sub('([a-z]*)@', '\\1-123@', s))


aaa-123@xxx.com bbb-123@yyy.com ccc-123@zzz.com

In [8]:
print(re.sub('([a-z]*)@', r'\1-123@', s))


aaa-123@xxx.com bbb-123@yyy.com ccc-123@zzz.com

In [9]:
t = re.subn('[a-z]*@', 'ABC@', s)
print(t)


('ABC@xxx.com ABC@yyy.com ABC@zzz.com', 3)

In [10]:
print(type(t))


<class 'tuple'>

In [11]:
print(t[0])


ABC@xxx.com ABC@yyy.com ABC@zzz.com

In [12]:
print(t[1])


3