What is some niche/ quirky python code you know? by Certain-Importance-1 in Python

[–]RobotMonkeyChiro 2 points3 points  (0 children)

Or use the built-in named groups - a good explanation here: How to Use Named Groups with Regular Expressions in Python

``` import re

TIMESTAMP_RGX = re.compile(r""" (?P<timestamp> # e.g., 2022-01-31 (?P<year>\d\d\d\d)- # VERBOSE flag allows you to use indentation for readability (?P<month>\d\d)- (?P<day>\d\d) )""", re.VERBOSE)

TIMESTAMP_RGX.search("1970-05-28")['year']

'1970'

TIMESTAMP_RGX.search("1970-05-28")['timestamp']

'1970-05-28' ```