Keywords searching via regexp

Eugene A.Tyurkin hackee at penguinpowered.com
Fri Oct 27 09:55:55 EDT 2000


Hi!
Here's a task
I have a list of keywords: keywords = ['qwerty','is','a','good','keyboard']
and want to find any of them in some text
The question is: how to write correct regexp to find them?
Notice, that I don't want to find words like 'goody', I want exectly my keywords
But I also want to find strings like 'qwerty', #good# etc
Here what I've tryed:

regexp = r"[^w]*\s+(" + string.join(keywords.'|') + r")"[^\w]*\s+"
aaa = re.compile(regexp)
...

It works fine, but it never find the word at the beginnig or the end of line.
Is it possible to make it all in one?

Thanx 




More information about the Python-list mailing list