On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong) <dannw...@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 -- http://mail.python.org/mailman/listinfo/python-list