Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50735 > unrolled thread
| Started by | Joshua Landau <joshua@landau.ws> |
|---|---|
| First post | 2013-07-16 09:42 +0100 |
| Last post | 2013-07-16 09:42 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: help on python regular expression named group Joshua Landau <joshua@landau.ws> - 2013-07-16 09:42 +0100
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-07-16 09:42 +0100 |
| Subject | Re: help on python regular expression named group |
| Message-ID | <mailman.4764.1373964225.3114.python-list@python.org> |
On 16 July 2013 07:55, Mohan L <l.mohanphy@gmail.com> 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?
Back to top | Article view | comp.lang.python
csiph-web