On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores <rdmoo...@gmail.com> wrote: > regex = ".*" + search + ".*" > p = re.compile(regex, re.I) > > in finding lines in a text file that contain search, a string entered > at a prompt.
That's an inefficient regex (though the compiler may be smart enough to prune the unneeded ".*"). Just having "search" as your regex is fine (it will search for the pattern _in_ the string, no need to specify the other parts of the string), but if you're not using any special regex characters you're probably better off not using a regex and just using a string operation. Regexes are great for trying to do powerful and complicated things - and as such may be too complicated if you're trying to do a simple thing. -- Brett Ritter / SwiftOne swift...@swiftone.org _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor