re = /^(?=(?P<LE10>(?:0[0-9]|1[0-9]|2[0-8]|3[0-7]|4[0-6]|5[0-5]|6[0-4]|7[0-3]|8[0-2]|9[0-1])))?(?:(?:X|(?P>LE10))-){9}(?:XXX|XX\d|X?(?P>LE10)|(?:19|28|37|46|55|64|7|3|82|91)[X\d])$/m
str = 'X-91-55-72-X-X-X-90-71-91X
X-91-55-72-X-X-X-90-82-XXX
X-91-55-72-X-X-X-90-82-XX7
X-91-55-72-X-X-X-90-82-X91
X-91-55-72-X-X-X-90-82-90
X-91-55-72-X-X-X-90-82-X91
X-91-55-72-X-X-X-90-82-917
X-91-72-X-X-X-90-82-917
Number of delimiters (8) incorrect
X-91-55-7-X-X-X-90-82-91X
7 in first 9 is invalid
X-91-55-72-X-X-X-X94-82-91X
X94 in first 9 is invalid
X-91-55-72-X-X-X-90-82-X
last = X is not valid
X-91-55-72-X-X-X-90-82-XX
last = XX is not valid
X-91-55-72-X-X-X-90-82-XXXX
last = XXXX is not valid
X-91-55-72-X-X-X-90-82-X92
last = X92 is not valid
X-91-55-72-X-X-X-90-82-94
last = 94 is not valid
X-91-55-72-X-X-X-90-82-62X
last = 62X is not valid
X-91-55-72-X-X-X-90-82-927
last = 927 is not valid
'
# 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