using System; using System.IO; using System.Text.RegularExpressions; public class Test { public static void Main() { var line = "@article{Gettys90,\n author = {Jim Gettys and Phil Karlton and Scott McGregor},\n abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler & Gettys.},\n journal = {Software Practice and Experience},\n volume = {20},\n number = {S2},\n title = {The {X} Window System, Version 11},\n year = {1990}\n\n},\n\n\n@article{Gettys90,\n author = {Jim Gettys and Phil Karlton and Scott McGregor},\n abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler & Gettys.},\n journal = {Software Practice and Experience},\n volume = {20},\n number = {S2},\n title = {The {X} Window System, Version 11},\n year = {1990}\n},\n@article{Gettys90,\n author = {Jim Gettys and Phil Karlton and Scott McGregor},\n abstract = {A technical overview of the X11 functionality. This is an update of the X10 TOG paper by Scheifler & Gettys.},\n\n journal = {Software Practice and Experience},\n\n volume = {20},\n number = {S2},\n title = {The {X} Window System, Version 11},\n year = {1990}\n}"; var kvp = @"(?\W*([a-zA-Z]+) = {(.+?)},)"; var pattern = string.Format("(?@(\\w+)\\{{(\\w+),{0}{0}*(\\W*([a-zA-Z]+) = \\{{(.+?)}})\\W*}},?\\s*)+", kvp); // No need to recurse (?) because we can just use `+` quantifier var matches = Regex.Matches(line, pattern); foreach (Match m in matches) Console.WriteLine(m.Groups["kvp"].Value); } }