egc> how do i write a regexp for this.. or better yet shd i even be using
egc> regexp or is there a better way to do this
"A team of engineers were faced with a problem; they decided to handle
it with regular expressions. Now they had two problems"
Regular expressions are not always the bes
On Fri, 19 Jan 2007 22:57:37 -0800, Rickard Lindberg wrote:
> Daniel Klein wrote:
>
>> 2) This can be resolved with
>>
>> templine = ' ' + line + ' '
>> if ' ' + word1 + ' ' in templine and ' ' + word2 + ' ' in templine:
>
> But then you will still have a problem to match the word "foo" in a
> s
Daniel Klein wrote:
> 2) This can be resolved with
>
> templine = ' ' + line + ' '
> if ' ' + word1 + ' ' in templine and ' ' + word2 + ' ' in templine:
But then you will still have a problem to match the word "foo" in a
string like "bar (foo)".
--
http://mail.python.org/mailman/listinfo/python
On 18 Jan 2007 18:54:59 -0800, "Rickard Lindberg"
<[EMAIL PROTECTED]> wrote:
>I see two potential problems with the non regex solutions.
>
>1) Consider a line: "foo (bar)". When you split it you will only get
>two strings, as split by default only splits the string on white space
>characters. Thus
Rickard Lindberg, yesterday I was sleepy and my solution was wrong.
> 2) If you have a line something like this: "foobar hello" then "'foo'
> in line" will return true, even though foo is not a word (it is part of
> a word).
Right. Now I think the best solution is to use __contains__ (in) to
quic
Rickard Lindberg wrote:
> I see two potential problems with the non regex solutions.
>
> 1) Consider a line: "foo (bar)". When you split it you will only get
> two strings, as split by default only splits the string on white space
> characters. Thus "'bar' in words" will return false, even though
Rickard Lindberg wrote:
> I see two potential problems with the non regex solutions.
>
> 1) Consider a line: "foo (bar)". When you split it you will only get
> two strings, as split by default only splits the string on white space
> characters. Thus "'bar' in words" will return false, even though
I see two potential problems with the non regex solutions.
1) Consider a line: "foo (bar)". When you split it you will only get
two strings, as split by default only splits the string on white space
characters. Thus "'bar' in words" will return false, even though bar is
a word in that line.
2) If
MrJean1 wrote:
> def lines_with_words(file, word1, word2):
> """Print all lines in file that have both words in it."""
> for line in file:
> words = line.split()
> if word1 in words and word2 in words:
> print line
This sounds better, it's probably faster than t
Without using re, this may work (untested ;-):
def lines_with_words(file, word1, word2):
"""Print all lines in file that have both words in it."""
for line in file:
words = line.split()
if word1 in words and word2 in words:
print line
/Jean Brouwers
Rickard
[EMAIL PROTECTED] wrote:
> Hi
>
> Am pretty new to python and hence this question..
>
> I have file with an output of a process. I need to search this file one
> line at a time and my pattern is that I am looking for the lines that
> has the word 'event' and the word 'new'.
>
> Note that i need lin
Hi
Am pretty new to python and hence this question..
I have file with an output of a process. I need to search this file one
line at a time and my pattern is that I am looking for the lines that
has the word 'event' and the word 'new'.
Note that i need lines that has both the words only and not
12 matches
Mail list logo