Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: help on python regular expression named group

Reply
Thread Tools

Re: help on python regular expression named group

 
 
Joshua Landau
Guest
Posts: n/a
 
      07-16-2013
On 16 July 2013 07:55, Mohan L <(E-Mail Removed)> wrote:
>
> 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


Why do you need to do this in a single Regex? Can't you just "
".join(..) the date and time?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help on python regular expression named group Mohan L Python 3 07-17-2013 08:00 AM
Named Group support for regular expressions in TR1? DomoChan@gmail.com C++ 3 08-12-2008 01:15 PM
Typed named groups in regular expression Hugo Ferreira Python 5 05-20-2007 10:40 AM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments