简体   繁体   中英

Regex for data inside nested curly braces?

I have the following record of data:

@INPROCEEDINGS{conf/icsm/Ceccato07,
  author = {Mariano Ceccato},
  title = {Migrating Object Oriented code to Aspect Oriented Programming},
  booktitle = {ICSM},
  year = {2007},
  pages = {497--498},
  publisher = {IEEE},
  bibdate = {2008-11-18},
  bibsource = {DBLP, http://dblp.uni-trier.de/db/conf/icsm/icsm2007.html#Ceccato07},
  crossref = {conf/icsm/2007},
  owner = {Administrator},
  timestamp = {2009.04.30},
  url = {http://dx.doi.org/10.1109/ICSM.2007.4362668}
}

Is there a way that i can get the following matchings such that each line is a separate match

  conf/icsm/Ceccato07
  author = Mariano Ceccato
  title = Migrating Object Oriented code to Aspect Oriented Programming
  booktitle = ICSM
  year = 2007
  pages = 497--498
  publisher = IEEE
  bibdate = 2008-11-18
  bibsource = DBLP, http://dblp.uni-trier.de/db/conf/icsm/icsm2007.html#Ceccato07
  crossref = conf/icsm/2007
  owner = Administrator
  timestamp = 2009.04.30
  url = http://dx.doi.org/10.1109/ICSM.2007.4362668

Here is my pattern which misses the first line match and doesn't bit get rid of the braces and the commas

string pattern = ".*[{].*}";

This regular expression, in Singleline mode, will grab everything inside the two outside braces:

(?<=\{).*(?=\})

Then you can use C# to strip out the interior braces:

var regex = new Regex(@"(?<=\{).*(?=\})", RegexOptions.Singleline);
var match = regex.Match(input);

return match.Value.Replace("{", string.Empty).Replace("}", string.Empty);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM