Module RE, Have a couple questions

Marc Huffnagle mhuffnagle at knowtechnology.net
Tue Mar 1 10:50:12 EST 2005


Dasacc

There is a better (faster/easier) way to do it than using the re module, 
the find method of the string class.

dasacc at gmail.com wrote:
> (1) How do I perform a search for "word" and have it return every line
> that this instance is found?

[line for line in document if line.find('a') != -1]

> 
> (2) How do I perform a search for "word" and "wordtwo" at the same time
> to return every line these instances are found so that the order in
> which these lines are in are left intact.

[line for line in document if (line.find('word') != -1 \
	and line.find('wordtwo'))]

> 
> If there's another standard module more suited for this let me know,
> and no I dont want to use sed :)
> 
> Thanks
> 



More information about the Python-list mailing list