From: Brian Candler Date: 2008-07-03T19:27:02+09:00 Subject: Re: any 3 letters > xxx765xxx should match > vvv123vvv should be omitted > > is it possible to write proper regular expression? Yes, it's possible, but you may find it less mind-bending just to use two regular expressions: puts "match" if foo =~ /\A[a-z]{3}\d{3}[a-z]{3}\z/ && foo !~ /\A...123/ If you really want a single regexp, then you can explicitly code a match for the allowed digit ranges: re = %r{\A [a-z]{3} ([02-9]\d\d | 1[013-9]\d | 12[0124-9]) [a-z]{3} \z}x Or you can be clever and use a negative look-ahead assertion: re = %r{\A [a-z]{3} (?!123) \d{3} [a-z]{3} \z}x Note that %r{...}x is just a way to write regexps with embedded spaces and newlines, so that they can be more easily understood. HTH, Brian.