From: Carlos Date: 2005-03-24T11:08:06+09:00 Subject: Re: (Maybe) a simple question about regex [Sam Kong , 2005-03-24 02.49 CET] > Hello! > > I think that I am missing a very simple concept about regex. > > s = '0123456789' > s.scan(/\d\d/) #-> ["01", "23", "45", "67", "89"] > > Now I want to exclude "45". > How can I express it in the regex? > When it's only one character, I can use ^. > But for 2 characters, I don't think I can use it. You can use a "negative lookahead assertion": s.scan(/(?!45)\d\d/) This means, at every point the regex tries to match, "if the next two characters aren't "45", match \d\d". HTH. --