regex function driving me nuts
cyberdicks at gmail.com
cyberdicks at gmail.com
Tue Oct 23 19:51:11 EDT 2012
Stripping the line did it !!!
Thank you very much to all !!!
Cheers! :-)
Martin
Le mardi 23 octobre 2012 16:36:44 UTC-4, Vlastimil Brom a écrit :
> 2012/10/23 MartinD.
>
> > Hi,
>
> >
>
> > I'm new to Python.
>
> > Does someone has an idea what's wrong. I tried everything. The only regex that is tested is the last one in a whole list of regex in keywords.txt
>
> > Thanks!
>
> > Martin
>
> >
>
> >
>
> > ########
>
> > def checkKeywords( str, lstKeywords ):
>
> >
>
> > for regex in lstKeywords:
>
> > match = re.search(regex, str,re.IGNORECASE)
>
> > # If-statement after search() tests if it succeeded
>
> > if match:
>
> > print match.group() ##just debugging
>
> > return match.group() ## 'found!
>
> >
>
> > return
>
> >
>
> > #########
>
> >
>
> > keywords1 = [line for line in open('keywords1.txt')]
>
> > resultKeywords1 = checkKeywords("string_to_test",keywords1)
>
> > print resultKeywords1
>
> >
>
> > --
>
> > http://mail.python.org/mailman/listinfo/python-list
>
>
>
> Hi,
>
> just a wild guess, as I don't have access to containing the list of
>
> potentially problematic regex patterns
>
> does:
>
> keywords1 = [line.strip() for line in open('keywords1.txt')]
>
> possibly fix yout problem?
>
> the lines of the file iterator also preserve newlines, which might not
>
> be expected in your keywords, strip() removes (be default) any
>
> starting and tryiling whitespace.
>
>
>
> hth,
>
> vbr
More information about the Python-list
mailing list