fork download
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. 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}";
  10. var kvp = @"(?<kvp>\W*([a-zA-Z]+) = {(.+?)},)";
  11. var pattern = string.Format("(?<entry>@(\\w+)\\{{(\\w+),{0}{0}*(\\W*([a-zA-Z]+) = \\{{(.+?)}})\\W*}},?\\s*)+", kvp);
  12. // No need to recurse (?<entry>) because we can just use `+` quantifier
  13. var matches = Regex.Matches(line, pattern);
  14. foreach (Match m in matches)
  15. Console.WriteLine(m.Groups["kvp"].Value);
  16.  
  17. }
  18. }
Success #stdin #stdout 0.12s 24704KB
stdin
Standard input is empty
stdout
   title = {The {X} Window System, Version 11},