4 ms·
Python (even in 2): >>> import re >>> pattern = re.compile(r"([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})") >>> results = pattern.ma
by Izkata 3y ago
Python (even in 2):
>>> import re
>>> pattern = re.compile(r"([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})")
>>> results = pattern.match('1973-01-05 09:30:00')
>>> results.groups()
('1973', '01', '05', '09', '30', '00')
>>> (y, m, d, h, min, s) = results.groups()
(`results` will be None if the regex didn't match)
Regexes are one of those things where, once you understand it (and capture groups in particular) and it's available in the language you're working in, string-splitting usually doesn't feel right anymore.
- burntsushi 3y agoI believe all of the people in this thread understand regexes extremely well. :-) There is a lot of reasonable room to disagree about when and where regexes should be used.