RE function

Ian Bicking ianb at colorstudy.com
Wed Nov 13 16:32:19 EST 2002


On Wed, 2002-11-13 at 15:15, lily wrote:
> 
> Hello,
> 
>  I need help. I am trying to parse some strings where I want to use the RE function. How can I find all the lines that start with '(object Operation' and should contain the word 'Trace' followed by ': {'  ?  
> 
> (object Operation...  
> 
> |Trace: {...}
> 
> 
> 
> ... ))
> 
> I tried using the following code to capture all the instances of these patterns:
> 
> tracepattern = re.compile("\(object\s+Operation<.*?>+\sTrace<.*?>\)")

You don't want those <>'s in there, just:

tracepattern = re.compile("\(object\s+Operation.*?\sTrace.*?\)")

(I also got rid of a + in <.*?>+)

Of course, this doesn't search for what you describe, it searched for
things like (object Operation some junk Trace some other junk) -- you
described {} in there somewhere, but that doesn't show up in your RE.

  Ian





More information about the Python-list mailing list