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


Groups > comp.lang.python > #11604

RE: regular expression

Subject RE: regular expression
Date 2011-08-16 14:09 -0500
References <BB13E4C4D649234F84A01F6DF64BB87F076AD0CE@ccs-ex01.coldstorage.com><4E499F0B.30900@stoneleaf.us><D59C59453D0EDC43832490B6DADFAECF04401A59@XMB-RCD-214.cisco.com> <CAMZYqRSt3prcXFwsU2Twig3_FDt2kHji0tqK3Fin5=_diZVrDw@mail.gmail.com>
From "Danny Wong (dannwong)" <dannwong@cisco.com>
Newsgroups comp.lang.python
Message-ID <mailman.97.1313521857.27778.python-list@python.org> (permalink)

Show all headers | View raw


Thanks chris. I had similar code to what you provided. I included the "#" (it was a comment in my code) as part of the string when it shouldn't be as part of my test. As soon as you pointed it out that the #'s aren't supposed to be part of the output, I removed them and it worked. How dumb of me. Thanks again.

-----Original Message-----
From: chris@rebertia.com [mailto:chris@rebertia.com] On Behalf Of Chris Rebert
Sent: Tuesday, August 16, 2011 12:26 AM
To: Danny Wong (dannwong)
Cc: python-list@python.org
Subject: Re: regular expression

On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong)
<dannwong@cisco.com> wrote:
> Hi All,
>        If I get multiline standard output from a command. How can I
> retrieve this part of the string "(1006)"
> Example:
>
> #Committing...
> #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0"
> #  Component: (1005) "he-Group" <-> (1004) "OS_8.12.0"
> #    Outgoing:
> #      Change sets:
> #        (1006)  *--@  <No comment>
> #          Changes:
> #            ---c- /he-Group/o-PI/target/config/common-ngp/makefile

Assuming the #s aren't in the actual output:

import re
pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE)
print(pat.search(your_str).group(1))

Obviously can vary depending on how you want to go about defining the
target string.

Cheers,
Chris

P.S. If you reply, please remove my email addresses from the quotation
due to "On Behalf Of" brokenness.
--
Freakin' Outlook/Exchange, I'm telling ya...
http://rebertia.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: regular expression "Danny Wong (dannwong)" <dannwong@cisco.com> - 2011-08-16 14:09 -0500

csiph-web