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


Groups > comp.lang.python > #11604 > unrolled thread

RE: regular expression

Started by"Danny Wong (dannwong)" <dannwong@cisco.com>
First post2011-08-16 14:09 -0500
Last post2011-08-16 14:09 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#11604 — RE: regular expression

From"Danny Wong (dannwong)" <dannwong@cisco.com>
Date2011-08-16 14:09 -0500
SubjectRE: regular expression
Message-ID<mailman.97.1313521857.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web