Keywords searching via regexp
hackee at penguinpowered.com
Fri Oct 27 15:55:55 CEST 2000
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?
More information about the Python-list