Skip to content

Commit e0418e9

Browse files
committed
Expose capture groups in rfc3339_datetime_re()
1 parent dabe300 commit e0418e9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/bd2k/util/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,20 @@ def rfc3339_datetime_re( anchor=True ):
151151
152152
>>> bool( rfc3339_datetime_re().match('9999-99-99T99:99:99.9-99:99') )
153153
True
154+
155+
If the regular expression matches, each component of the matching value will be exposed as a
156+
captured group in the match object.
157+
158+
>>> rfc3339_datetime_re().match('2013-11-06T15:56:39Z').groups()
159+
('2013', '11', '06', '15', '56', '39', None, 'Z')
160+
>>> rfc3339_datetime_re().match('2013-11-06T15:56:39.123Z').groups()
161+
('2013', '11', '06', '15', '56', '39', '123', 'Z')
162+
>>> rfc3339_datetime_re().match('2013-11-06T15:56:39.123-08:30').groups()
163+
('2013', '11', '06', '15', '56', '39', '123', '-08:30')
154164
"""
155165
return re.compile(
156166
('^' if anchor else '') +
157-
'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})' +
167+
'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})' +
158168
('$' if anchor else '') )
159169

160170

0 commit comments

Comments
 (0)