re = /(?xi)^( (DE)?[0-9]{9}|)$/m
str = 'ATU99999999
BE0999999999
BG999999999
HR12345678901
CY99999999L
CZ12345678
DK99999999
EE123456789
FI99999999
FRXX999999999
DE999999999
EL123456789
HU12345678
IE1S23456L
IE1234567T
IE1234567TW
IE1234567FA
ESA12345678
ESZ1234567E
DE813992525'
# 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