String Problem

Colin Meeks colinmeeks at home.com
Mon May 14 16:19:36 EDT 2001


I have the following problem and was wondering how people would go about
solving it.

I have a variable string with different keywords in it.  What I would like
to do is trim the string so that it has X words either side of the requested
keywords.

i.e. what light through yonder window breaks, tis in the East and Juliet is
the sun.

I would like to specify say, Yonder and East and trim the trim to x words
around it.  So if I wanted 2 words either side I would end up with

"light through yonder window breaks, tis in the East and Juliet"

I'm trying to write a small search engine.  Although I could write a mass of
code to do what I want, I was wondering if a regular expression could be
used, or anything else, similarly simplistic.?

Colin





More information about the Python-list mailing list