[Solved] date extraction through regex [closed]


Without regex:

s = "20160204094836A"

year = s[:4]
day = s[4:6]
month = s[6:8]

print(year, day, month)

With Regex:

import re

s = "20160204094836A"
result = re.search(r"^(\d{4})(\d{2})(\d{2})", s)
year = int(result.group(1))
day = int(result.group(2))
month = int(result.group(3))

print(year, day, month)

solved date extraction through regex [closed]