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: 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: References: Date: Tue, 3 Jan 2012 10:21:48 -0500 Subject: Re: [Tutor] Parse multi line with re module. From: Joel Goldstick To: Ganesh Kumar 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, Jan 3, 2012 at 9:13 AM, Ganesh Kumar 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 =3D re.compile("^Searching for OPUSH on (\w\w(:\w\w)+)") > > for channel finding > > device_r =3D 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 =C2=A0- =C2=A0Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > --=20 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 =3D "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 add= ress >>> 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