re = /(?<ChapterAuthors>[A-Z'a-z,\s]+?)(?: et al)?:(?<ChapterTitle>[A-Za-z,#\(\)\/0-9"’'&\sö]+)\.\s?In\s?(?<BookAuthors>[A-Za-z,\s]+?)(?: et al)?:(?<BookTitle>[A-Za-z,#\(\)0-9"’'&\s]+)\.\s?(?<Edition>\d+(?:rd|nd|st|th)\s(?:[eE]d|[eE]dition|))\.(?<Location>[-A-Za-z,.\s]+):(?<Publisher>[-A-Za-z,\(\)\/&\s]+)[\.]\s?(?<StartPage>\w?\d+\w?)-\s?(?<EndPage>\w?\d+\w?)[,\.;]\s?(?<Year>\d{4})/
str = 'Johnson M: Amino acids and proteins. In Burtis CA et al: Tietz Fundamentals of Clinical Chemistry. 6th ed. St. Louis: Saunders. 286-310, 2008
Dufour DR: Liver disease. In Burtis CA et al: Tietz Fundamentals of Clinical Chemistry. 6th ed. St. Louis: Saunders. 675-95, 2008
Cunningham FG et al: Diseases and abnormalities of the placenta. In: Licht J, ed. Williams\'s obstetrics. 19th ed. Norwalk, Conn: Appleton & Lange. 748-59, 1993
Tille PM: Enterobacteriaceae. In Tille PM: Bailey & Scott’s Diagnostic Microbiology. 13th ed. St. Louis: Mosby. 307-28, 2013'
# 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