Keywords searching via regexp

Quinn Dunkan quinn at bolivar.ugcs.caltech.edu
Sat Oct 28 01:44:05 EDT 2000


On Fri, 27 Oct 2000 21:55:55 +0800 (KRAST), Eugene A.Tyurkin
<hackee at penguinpowered.com> wrote:
>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)
>...

See the '\b' code in the re docs.



More information about the Python-list mailing list