From: "David A. Black" Date: 2008-07-03T19:48:27+09:00 Subject: Re: yet another regexp problem Hi -- On Thu, 3 Jul 2008, shaman wrote: > Hello- > > I need to match any string which contain: > > any 3 letters > any 3 digits _but_not_123_ > any 3 letters > > so: > xxx765xxx should match > vvv123vvv should be omitted Try this: /[[:alpha]]{3}(?!123)\d{3}[[:alpha:]]{3}/ It uses negative lookahead. The \d{3} part only matches if it occurs at a point where the next thing in the string is not "123". I'm also using the POSIX "alpha" character class, which should be locale-sensitive. You can also use [A-Za-z] if that's sufficient. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates!