re = /^XXX-\d{4}-((?![XYT])[A-Z]){4}$/m
str = 'XXX-0000-XBCD
XXX-0000-AXCD
XXX-0000-ABXD
XXX-0000-ABCX
XXX-0000-XXCD
XXX-0000-XBXD
XXX-0000-XBCX
XXX-0000-AXXD
XXX-0000-AXCX
XXX-0000-ABXX
XXX-0000-XXXX
XXX-0000-AB1D
XXX-0000-A%CD
XXX-0000-ABCDE
XXX-0000-ABCDX
AXXX-0000-ABCD
XXX-A0000-ABCD
XXX-0000-ABCD
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html