Here is how I would capture all the details in the line that you provided:
@(?<type>\w+)\{(?<name>\w+),(?<kvps>\s*(?<attribute>\w+)\s*=\s*\{(?<value>.*?)},?\r?\n)+}
Watch the demo
This regex works well because the C # regex engine saves all captured texts on the stack and can be accessed through Groups ["name"]. Captures .
C # code showing how to use it:
var pattern = @"@(?<type>\w+)\{(?<name>\w+),(?<kvps>\s*(?<attribute>\w+)\s*=\s*\{(?<value>.*?)},?\r?\n)+}"; var matches = Regex.Matches(line, pattern); var cnt = 1; foreach (Match m in matches) { Console.WriteLine(string.Format("\nMatch {0}", cnt)); Console.WriteLine(m.Groups["type"].Value); Console.WriteLine(m.Groups["name"].Value); for (int i = 0; i < m.Groups["attribute"].Captures.Count; i++) { Console.WriteLine(string.Format("{0} - {1}", m.Groups["attribute"].Captures[i].Value, m.Groups["value"].Captures[i].Value)); } cnt++; }
Output:
Match 1 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 Match 2 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 Match 3 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
source share