PDA

View Full Version : problem with searching in python



freemanen
March 4th, 2006, 11:37 PM
for line in file("hej.txt","r"):
if(re.search(r"*\www*\",line))

i would like it to search for everything that contains *www* but only that string not the whole line. like dfdsfwwwdfdsf or ddsfsdwwwöäåq

LordHunter317
March 5th, 2006, 12:47 AM
I'm confused. You'll have to define what you mean by "string" then. You're delimiting based on lines. If you want to delimit based on something else instead, you need to do that. For example, if you want to search based on words, you need to split via whitespace first, then search.

Van_Gogh
March 5th, 2006, 11:34 PM
I'm not really sure what you want either, but if what you want is search for if the string "www" is in a line you can do:



for line in file("hej.txt","r"):
if "www" in line.lower():
do_something()


by using line.lower() above we get positives for both lower mixed and upper cases, that is "Www", "www" and "WWW" will all be ok.

If what you want is different than what is above, you'll probably need to be more precise.