On Tue, 8 Mar 2005, Mike Hall wrote:

> I'd like to get a match for a position in a string preceded by a
> specified word (let's call it "Dog"), unless that spot in the string
> (after "Dog") is directly followed by a specific word(let's say "Cat"),
> in which case I want my match to occur directly after "Cat", and not
> "Dog."

Hi Mike,

You may want to look at "lookahead" assertions.  These are patterns of the
form '(?=...)' or '(?!...).  The documentation mentions them here:

   http://www.python.org/doc/lib/re-syntax.html

and AMK's excellent "Regular Expression HOWTO" covers how one might use
them:

http://www.amk.ca/python/howto/regex/regex.html#SECTION000540000000000000000

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to