help on python regular expression named group
Mohan L
l.mohanphy at gmail.com
Tue Jul 16 02:55:58 EDT 2013
Dear All,
Here is my script :
#!/usr/bin/python
import re
# A string.
logs = "date=2012-11-28 time=21:14:59"
# Match with named groups.
m =
re.match("(?P<datetime>(date=(?P<date>[^\s]+))\s+(time=(?P<time>[^\s]+)))",
logs)
# print
print m.groupdict()
Output:
========
{'date': '2012-11-28', 'datetime': '*date=2012-11-28 time=21:14:59*',
'time': '21:14:59'}
Required output :
==================
{'date': '2012-11-28', 'datetime': '*2012-11-28 21:14:59*', 'time':
'21:14:59'}
need help to correct the below regex
(?P<datetime>(date=(?P<date>[^\s]+))\s+(time=(?P<time>[^\s]+)))"
so that It will have : 'datetime': '2012-11-28 21:14:59' instead of
'datetime': 'date=2012-11-28 time=21:14:59'
any help would be greatly appreciated
Thanks
Mohan L
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130716/a8891044/attachment.html>
More information about the Python-list
mailing list