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


Groups > comp.lang.python > #50735

Re: help on python regular expression named group

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'string.': 0.05; 'subject:group': 0.05; 'subject:help': 0.08; 'cc:addr :python-list': 0.11; 'subject:expression': 0.16; 'subject:regular': 0.16; 'subject:python': 0.16; 'skip:= 10': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'all,': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'script': 0.25; 'appreciated': 0.26; 'header:In- Reply-To:1': 0.27; 'correct': 0.29; 'skip:( 40': 0.30; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; 'skip:# 10': 0.33; "can't": 0.35; 'received:google.com': 0.35; 'logs': 0.60; 'july': 0.63; 'dear': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'groups.': 0.74; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=n470ifAYHkYRwulkfddcS41261L1OslpDc02y7p+bm4=; b=rcvC0Uzl27CH0MprL9JFPiG0BO5BdrW3nZRR3OPayqd4KIbs5yAn+k3Y8ZuenFOIys j6mzvZJA3bgBkoam98JoP9QTlXKZHEG5u9U2jtGb1+EHZXcDGW/BU6MDLzZ7MP3Ptrdi o19higzkLPklaCUDUL8Jbacy0XxDpdUL7ZapMx16hAcwQKsh183SfHTnIE6HCstS5a4Q a1wv/1kgaOJMWlGtHio7drzvriGLoTkUcBD9Tr2sDNffLWPkIzWlm6hIcGrW7DHx/HI1 sVxAv/xC6zwtg/7kXEtaT9tMExA2q85clGrD2u1kZrhCogxNSLtGdxKvi1thss3trCdC heWw==
X-Received by 10.152.121.73 with SMTP id li9mr232181lab.42.1373964216909; Tue, 16 Jul 2013 01:43:36 -0700 (PDT)
MIME-Version 1.0
Sender joshua.landau.ws@gmail.com
In-Reply-To <CADiHtmufOLNysgOP7Qoh70_aT+r3rhKFS=9qgd_AcDNgEFVnqw@mail.gmail.com>
References <CADiHtmufOLNysgOP7Qoh70_aT+r3rhKFS=9qgd_AcDNgEFVnqw@mail.gmail.com>
From Joshua Landau <joshua@landau.ws>
Date Tue, 16 Jul 2013 09:42:56 +0100
X-Google-Sender-Auth EhTg8JDlidLXvsHgPhOHhiknM6A
Subject Re: help on python regular expression named group
To Mohan L <l.mohanphy@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4764.1373964225.3114.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373964225 news.xs4all.nl 15900 [2001:888:2000:d::a6]:34901
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50735

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: help on python regular expression named group Joshua Landau <joshua@landau.ws> - 2013-07-16 09:42 +0100

csiph-web