[Tutor] regular expression question

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Mar 9 03:05:36 CET 2005

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:


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


More information about the Tutor mailing list