re = /^(?:((?:IT|SM)\d{2}[A-Z]{1}\d{22})|(NL\d{2}[A-Z]{4}\d{10})|(LV\d{2}[A-Z]{4}\d{13})|((?:BG|GB|IE)\d{2}[A-Z]{4}\d{14})|(GI\d{2}[A-Z]{4}\d{15})|(RO\d{2}[A-Z]{4}\d{16})|(MT\d{2}[A-Z]{4}\d{23})|(NO\d{13})|((?:DK|FI)\d{16})|((?:SI)\d{17})|((?:AT|EE|LU|LT)\d{18})|((?:HR|LI|CH)\d{19})|((?:DE|VA)\d{20})|((?:AD|CZ|ES|MD|SK|SE)\d{22})|(PT\d{23})|((?:IS)\d{24})|((?:BE)\d{14})|((?:FR|MC|GR)\d{25})|((?:PL|HU|CY)\d{26}))$
/m
str = 'AD1400080001001234567890
AT483200000012345864
BE71096123456769
BG18RZBB91550123456789
HR1723600001101234565
CY21002001950000357001234567
CZ5508000000001234567899
DK9520000123456789
EE471000001020145685
FI1410093000123458
FR7630006000011234567890189
DE75512108001245126199
GI04BARC000001234567890
GR9608100010000001234567890
HU93116000060000000012345676
IS750001121234563108962099
IE64IRCE92050112345678
IT60X0542811101000000123456
LV97HABA0012345678910
LI7408806123456789012
LT601010012345678901
LU120010001234567891
MT31MALT01100000000000000000123
MC5810096180790123456789085
NL02ABNA0123456789
NO8330001234567
PL10105000997603123456789123
PT50002700000001234567833
RO09BCYP0000001234567890
SM76P0854009812123456789123
SK8975000000000012345671
SI56192001234567892
ES7921000813610123456789
SE7280000810340009783242
CH5604835012345678009
GB33BUKB20201555555555
VA59001123000012345678
AL35202111090000000001234567
AZ96AZEJ00000000001234567890
BH02CITI00001077181611
BA393385804800211234
BR1500000000000010932840814P2
CR23015108410026012345
FO9264600123456789
GL8964710123456789
DO22ACAU00000000000123456789
EG800002000156789012345180002
GE60NB0000000123456789
GT20AGRO00000000001234567890
IL170108000000012612345
JO71CBJO0000000000001234567890
KZ563190000012344567
XK051212012345678906
KW81CBKU0000000000001234560101
LB92000700000000123123456123
MK07200002785123453
MR1300020001010000123456753
MU43BOMM0101123456789101000MUR
MD21EX000000000001234567
ME25505000012345678951
PK36SCBL0000001123456702
PS92PALS000000000400123456702
QA54QNBA000000000000693123456
LC14BOSL123456789012345678901234
ST23000200000289355710148
SA4420000001234567891234
RS35105008123123123173
TL380010012345678910106
TN5904018104004942712345
TR320010009999901234567890
AE460090000000123456789
VG21PACG0000000123456789
UA903052992990004149123456789
SC52BAHL01031234567890123456USD
IQ20CBIQ861800101010500
BY86AKBB10100000002966000000
SV43ACAT00000000000000123123
LY38021001000000123456789
SD8811123456789012
test'
# 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