Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18417
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joel.goldstick@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'subject:: [': 0.02; 'cc:addr:tutor': 0.09; 'parsing': 0.09; 'subject:Tutor': 0.09; 'am,': 0.12; 'subject:] ': 0.14; '9:13': 0.16; 'guys,': 0.16; '\xc2\xa0-': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'simpler': 0.18; 'working.': 0.18; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'slice': 0.23; 'defined': 0.24; 'string': 0.24; 'code': 0.25; 'url:mailman': 0.28; 'channel': 0.28; 'message-id:@mail.gmail.com': 0.28; 'module.': 0.29; "skip:' 10": 0.29; 'cc:addr:python.org': 0.29; 'pattern': 0.30; 'url:library': 0.31; 'skip:_ 40': 0.31; 'capture': 0.32; 'tue,': 0.32; 'url:listinfo': 0.32; 'done': 0.34; 'it.': 0.34; 'options:': 0.34; 'parse': 0.34; 'something': 0.35; 'url:python': 0.36; 'received:209.85.161': 0.36; '...': 0.36; 'subject:with': 0.36; 'cc:2**1': 0.36; 'pull': 0.37; 'two': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'not,': 0.37; 'received:209.85': 0.38; 'finding': 0.39; 'url:docs': 0.39; 'url:org': 0.39; 'received:209': 0.40; 'url:net': 0.60; 'address': 0.61; 'your': 0.61; '2012': 0.67; 'url:show': 0.67; 'unsubscribe': 0.79; 'channel,': 0.84; 'so:': 0.84; 'url:tutor': 0.84; 'joel': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=hb+Q3Cjs/TS265DN+4hw/RLcJNA6Iq8zRoeuX+1Psw8=; b=bAzZGwP6dX5oieXFgy92/Xs/CUIx942YqS9HKErcmezYdnsiEFeFoT8LNDaq8ij+kL dcZ4/l6zL2QfGig68Zx217Ydkst4qV7hMC2Ao/W4HvucGBEEofCXR6VTqR6ksQyuAQBC 9Qcvz6K/VBYXLktyuuo5rzRV/BzoApos6Rpe4= |
| MIME-Version | 1.0 |
| In-Reply-To | <CAJzooYdBNYmYRChySBhAHymd_+e_D-7yTG9juC0+__1BJ-Qr3w@mail.gmail.com> |
| References | <CAJzooYdBNYmYRChySBhAHymd_+e_D-7yTG9juC0+__1BJ-Qr3w@mail.gmail.com> |
| Date | Tue, 3 Jan 2012 10:21:48 -0500 |
| Subject | Re: [Tutor] Parse multi line with re module. |
| From | Joel Goldstick <joel.goldstick@gmail.com> |
| To | Ganesh Kumar <bugcy013@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org, tutor@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.4356.1325604112.27778.python-list@python.org> (permalink) |
| Lines | 61 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1325604112 news.xs4all.nl 6864 [2001:888:2000:d::a6]:33196 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18417 |
Show key headers only | View raw
On Tue, Jan 3, 2012 at 9:13 AM, Ganesh Kumar <bugcy013@gmail.com> wrote:
> Hi Guys,
>
> I want parse multiple line. with re.module, this is my given string
> http://dpaste.com/680760/ I have try with re.compile module. I want parse
> two line mac address and channel,
> I have done with for mac address finding
>
> r = re.compile("^Searching for OPUSH on (\w\w(:\w\w)+)")
>
> for channel finding
>
> device_r = re.compile("^Channel: (\d+)")
>
> the two parsing string working. but I want combine two pattern in to one.
>
> This is my code
> http://www.bpaste.net/show/21323/
>
> please guide me .
>
>
> -Ganesh
>
> Did I learn something today? If not, I wasted it.
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Do you know about str.startswith()
http://docs.python.org/library/stdtypes.html#str.startswith
Since your data is so well defined I think it would be simpler to just
read each line, strip whitespace, use startswith() to check for
"Searching for OPUSH on" and "Channel:"
You can slice to pull out the mac address and the channel number like so:
>>> s = "Searching for OPUSH on 00:1D:FD:06:99:99"
>>> s[23:]
'00:1D:FD:06:99:99' # this will work if no other text follows the mac address
>>> s[23:41]
'00:1D:FD:06:99:99' # this will work to just capture the mac address
>>>
For the Channel number, after stripping whitespace, take the slice from s[9:]
Searching for OPUSH on 00:1D:FD:06:99:99 ...
Channel: 9
Joel Goldstick
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: [Tutor] Parse multi line with re module. Joel Goldstick <joel.goldstick@gmail.com> - 2012-01-03 10:21 -0500
csiph-web