In [28]:
import re
In [29]:
pattern = re.compile(r'hello.*\!')
In [30]:
match = pattern.match('hello world!hello python')
In [31]:
if match:
print(match.group())
In [32]:
print(match.string)
In [33]:
print(match.groups())
In [34]:
print(match.span())
In [35]:
p = re.compile(r'\d+')
In [36]:
print(p.split('one1two2three3four4'))
In [37]:
print(p.findall('one1two2three3four4'))
In [38]:
p = re.compile(r'(\w+) (\w+)')
s = 'i say hello thushear'
print(p.sub(r'\2\1',s))
In [ ]: