re = /(?<entry>@(\w+)\{(\w+),(?<kvp>\W*([a-zA-Z]+) = \{(.+)\},)(?&kvp)*(\W*([a-zA-Z]+) = \{(.+)\})\W*\},?\s*)(?&entry)*/
str = '@article{Gettys90,
author = {Jim Gettys and Phil Karlton and Scott McGregor},
abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \\& Gettys.},
journal = {Software Practice and Experience},
volume = {20},
number = {S2},
title = {The {X} Window System, Version 11},
year = {1990}
},
@article{Gettys90,
author = {Jim Gettys and Phil Karlton and Scott McGregor},
abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \\& Gettys.},
journal = {Software Practice and Experience},
volume = {20},
number = {S2},
title = {The {X} Window System, Version 11},
year = {1990}
},
@article{Gettys90,
author = {Jim Gettys and Phil Karlton and Scott McGregor},
abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler \\& Gettys.},
journal = {Software Practice and Experience},
volume = {20},
number = {S2},
title = {The {X} Window System, Version 11},
year = {1990}
}'
# 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