Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50746
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.017 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; '16,': 0.03; 'output': 0.05; 'string.': 0.05; 'subject:group': 0.05; 'subject:help': 0.08; 'python': 0.11; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'substring': 0.16; 'subject:python': 0.16; 'skip:= 10': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; '(the': 0.22; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'lets': 0.24; 'script.': 0.24; 'file.': 0.24; 'script': 0.25; 'appreciated': 0.26; 'asking': 0.27; 'header:In- Reply-To:1': 0.27; 'correct': 0.29; 'skip:( 40': 0.30; "skip:' 10": 0.31; 'that.': 0.31; 'another': 0.32; 'skip:# 10': 0.33; 'third': 0.33; "can't": 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'remove': 0.60; 'logs': 0.60; "you're": 0.61; 'july': 0.63; 'dear': 0.65; 'here': 0.66; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'groups.': 0.74; 'jul': 0.74; 'captures': 0.84; 'reply-to:addr:python.org': 0.84; 'substrings': 0.84; 'together,': 0.84; 'capture': 0.91; 'time)': 0.91; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=bqsVwSV3o_cA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=My1DXVzExXUA:10 a=sfeZhN6MAAAA:8 a=pGLkceISAAAA:8 a=7TDE6NsTis3iVeQY1Q4A:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Tue, 16 Jul 2013 16:38:14 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: help on python regular expression named group |
| References | <CADiHtmufOLNysgOP7Qoh70_aT+r3rhKFS=9qgd_AcDNgEFVnqw@mail.gmail.com> <CAN1F8qUpxVuNV-9+9NT1zCzkXQKMMwMtTdCv0+TJ-P9wnigcjg@mail.gmail.com> <CADiHtmum9=otNTuFCwwzsmyKSq_4126D2AnpdWoXGBhEABZHow@mail.gmail.com> |
| In-Reply-To | <CADiHtmum9=otNTuFCwwzsmyKSq_4126D2AnpdWoXGBhEABZHow@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| 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.4774.1373989068.3114.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1373989068 news.xs4all.nl 15888 [2001:888:2000:d::a6]:39735 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50746 |
Show key headers only | View raw
On 16/07/2013 11:18, Mohan L wrote:
>
>
>
> On Tue, Jul 16, 2013 at 2:12 PM, Joshua Landau <joshua@landau.ws
> <mailto:joshua@landau.ws>> wrote:
>
> On 16 July 2013 07:55, Mohan L <l.mohanphy@gmail.com
> <mailto: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?
>
>
> I using another third party python script. It takes the regex from
> configuration file. I can't write any code. I have to do all this in
> single regex.
>
A capture group captures a single substring.
What you're asking is for it to with capture 2 substrings (the date and
the time) and then join them together, or capture 1 substring and then
remove part of it.
I don't know of _any_ regex implementation that lets you do that.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: help on python regular expression named group MRAB <python@mrabarnett.plus.com> - 2013-07-16 16:38 +0100
csiph-web