re = /(?<type>[A-Za-z]{1})(?<subtype>[A-Za-z<]{1})(?<expcountry>[A-Za-z]{3})(?<docnumber>[0-9A-Za-z<]{9})(?<docnumbercheck>[0-9]{1})(?<complement>[0-9a-zA-Z<]{15})\n(?<birthdate>[0-9]{6})(?<birthcheck>[0-9]{1})(?<sex>[mfMF]{1})(?<expiredate>[0-9]{6})(?<expirecheck>[0-9]{1})(?<nacionality>[A-Za-z]{3})(?<optional>[a-zA-Z0-9<]{11})(?<linecheck>[0-9]{1})\n(?<lname>[A-Z]+)(?<lname2><[A-Z]+){0,}<<(?<spacing>[<]{0,})(?<fname>[A-Z]+)(?<mname1><[A-Z]+){0,}(?<namecomplement>[a-zA-Z<]+){0,}/
str = 'IDCHES0002068<8<<<<<<<<<<<<<<<
8102287F1301014CHE<<<<<<<<<<<4
VADIS<<QUO<<<<<<<<<<<<<<<<<<<<
I<UTOD231458907<<<<<<<<<<<<<<<
7408122F1204159UTO<<<<<<<<<<<6
ERIKSSON<<ANNA<MARIA<<<<<<<<<<
I<NLDXI020DF236123456783<<<<<<
7208148F1108268NLD<<<<<<<<<<<9
VAN<DER<STEEN<<MARIANNE<LOUISE'
# Print the match result
str.match(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