Module RE, Have a couple questions
Marc Huffnagle
mhuffnagle at knowtechnology.net
Tue Mar 1 10:52:18 EST 2005
Oops, made a mistake.
Marc Huffnagle wrote:
> 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'))]
This should have been:
[line for line in document if (line.find('word') != -1 \
and line.find('wordtwo') != -1)]
>
>>
>> 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