help on python regular expression named group

M

Mohan L

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
 
W

wxjmfauth

Le mardi 16 juillet 2013 08:55:58 UTC+2, Mohan L a écrit :
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

------

Not sure, I'm correct. I took you precise string to
refresh my memory.


jmf
 
J

Joshua Landau

Not sure, I'm correct. I took you precise string to
refresh my memory.

I'm glad to see you doing something else, but I don't think you
understood his problem. Note that his problem has not solution, which
a few seconds of Googling has confirmed to me.
 
W

wxjmfauth

Le mercredi 17 juillet 2013 09:46:46 UTC+2, Joshua Landau a écrit :
I'm glad to see you doing something else, but I don't think you

understood his problem. Note that his problem has not solution, which

a few seconds of Googling has confirmed to me.

Right.

I did not pay attention to "date", "time" *and* "datetime".

jmf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top