re
import re
<re.Match object; span=(0, 9), match='a1234456d'>
r = 'a1234456d'
re_c = re.compile(r'a\d+d')
res = re.match(re_c, r)
print(res)
<re.Match object; span=(0, 9), match='a1234456d'>
re_c = re.compile(r'a\d+4')
res = re.search(re_c,r)
print(res)
<re.Match object; span=(0, 6), match='a12344'>
repl = '321'
re_c = re.compile(r'a\d+3')
res = re.sub(re_c, repl, r, 1)
print(res)
3214456d
re_c = re.compile(r'\d')
print(re_c.findall(r))
['1', '2', '3', '4', '4', '5', '6']
res = re.finditer(re_c, r)
print(res)
for i in res:
print(i.group())
<callable_iterator object at 0x000001EB33304688>
1
2
3
4
4
5
6
res = re.split(re_c, r)
print(res)
['a', '', '', '', '', '', '', 'd']
r = r'a123b345b'
re_c = re.compile(r'a.+b')
res = re_c.findall(r)
print(res)
['a123b345b']
re_c = re.compile(r'a(.+?)b')
res = re_c.findall(r)
print(res)
['123']