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


hello world!

In [32]:
print(match.string)


hello world!hello python

In [33]:
print(match.groups())


()

In [34]:
print(match.span())


(0, 12)

In [35]:
p = re.compile(r'\d+')

In [36]:
print(p.split('one1two2three3four4'))


['one', 'two', 'three', 'four', '']

In [37]:
print(p.findall('one1two2three3four4'))


['1', '2', '3', '4']

In [38]:
p = re.compile(r'(\w+) (\w+)')
s = 'i say hello thushear'
print(p.sub(r'\2\1',s))


sayi thushearhello

In [ ]: