import re
s = 'my name is mike'
print(s.split())
p = re.compile(r'\W+')
print(p.split(s))
p = re.compile('blue|white|red')
print(p.sub('colour', 'blue socks and red shoes'))
print(p.sub('colour', 'blue socks and red shoes', count=1))
print(p.subn('colour', 'blue socks and red shoes'))
Execution result:
['my', 'name', 'is', 'mike']
['my', 'name', 'is', 'mike']
colour socks and colour shoes
colour socks and red shoes
('colour socks and colour shoes', 2)