From: "F. Senault" Date: 2008-07-03T20:32:02+09:00 Subject: Re: yet another regexp problem Le 03 juillet � 12:48, David A. Black a �crit : >> 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. Note that, sometimes, it's easier / more efficient to use RegExpen to find slightly too many matches and then filter them afterwards. Something like : "xxx765xxx vvv123vvv zzz555ooo".\ scan(/([A-Za-z]{3}([0-9]{3})[A-Za-z]{3})/) do |all, num| puts all unless num == "123" end Fred -- When you like music more than life, something's wrong When you start sleeping as you drive, something's wrong When you're favorite drink is thinner, something's wrong When you're proud to be a sinner... (K's Choice, Something's wrong)