pikapython/examples/re/findall.py

8 lines
262 B
Python
Raw Normal View History

import re
2022-08-29 18:09:45 +08:00
pattern = re.compile('(\\d{4})-([1-9]|1[0-2])-([1-9]|[1-2][0-9]|3[01])\\b')
s = 'date: 2020-1-1, 2022-12-22, 2018-3-31. Wrong format: 2031-13-31, 2032-12-33 ...'
result1 = pattern.findall(s)
print(result1)
2022-08-29 18:09:45 +08:00
result2 = pattern.sub('\\1',s)
print(result2)