mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
8 lines
259 B
Python
8 lines
259 B
Python
|
import re
|
||
|
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)
|
||
|
result2 = pattern.sub('\1',s)
|
||
|
print(result2)
|