Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50731

help on python regular expression named group

Date 2013-07-16 12:25 +0530
Subject help on python regular expression named group
From Mohan L <l.mohanphy@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4760.1373960601.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

help on python regular expression named group Mohan L <l.mohanphy@gmail.com> - 2013-07-16 12:25 +0530
  Re: help on python regular expression named group wxjmfauth@gmail.com - 2013-07-16 23:15 -0700
    Re: help on python regular expression named group Joshua Landau <joshua@landau.ws> - 2013-07-17 08:46 +0100
      Re: help on python regular expression named group wxjmfauth@gmail.com - 2013-07-17 01:00 -0700

csiph-web