Match a complex pattern to determine whether a string is a valid Roman number (up to decimal 3999).
#!/usr/local/bin/ruby
# Match a complex pattern to determine whether a string is a
# valid Roman number (up to decimal 3999). The pattern is
# broken up into parts for readability
rom1 = /m{0,3}/i
rom2 = /(d?c{0,3}|c[dm])/i
rom3 = /(l?x{0,3}|x[lc])/i
rom4 = /(v?i{0,3}|i[vx])/i
roman = /^#{rom1}#{rom2}#{rom3}#{rom4}$/
year1985 = "MCMLXXXV"
if year1985 =~ roman
puts "yes"
else
puts "no"
end