re = /^\w(\d{1,})\.\w(\d{0,2})/m
str = 'B43.C21.D10.E110
B52.C21.D22.E000
B52.C21.D22.E000
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D10.E120
B42.C11.D20
B42.C11.D20
B46.C71.D11.E000
B81.C21.D10.E000
B80.C20.D10.E000
B81.C10.D10.E000
B35.C11.D10.E116
B19.C20.D2
B81.C10.D10.E000
B80.C20.D10.E000
B46.C3
B36.C00.D11.E000'
# 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