How about `sha1 =~ /^[0-9a-fA-F]{40}$/`? `deadbeef` shouldn't match, but 40 `a`'s should.