Regular Expression - newbie question

SK skunix at hotmail.com
Sun Aug 25 23:03:14 EDT 2002


I want to search for a pattern across multiple lines:-
  
Pattern: "python output" followed by anything without "python output"
again and then "Hello World"

Input File (c.txt)
----------
This is my file
This is one python output
This is my file
This is two python output
This is my file
Hello World

The following code snippet matches only 
  This is one python output
  Hello World

But I am interested only in the following:-
   This is two python output
   Hello World


Code Snippet
============
import re
data = open("c.txt","rb").read()
regexp = "(^.*python output.*$)[\000-\377]*?(^.*Hello World.*$)"
r = re.compile(regexp,re.M)
match = re.findall(r, data)
print match

Desired Output Match
====================
This is two python output
Hello World

Any good pointers/books for regular expressions in Python appreciated.

Thanks.



More information about the Python-list mailing list