我有以下数据记录:
@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}
}
有没有办法可以获得以下匹配,以便每一行都是一个单独的匹配
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
这是我的模式,错过了第一行匹配,并没有删掉括号和逗号
string pattern = ".*[{].*}";
答案 0 :(得分:1)
这个正则表达式,在单行模式下,将抓住两个外部括号内的所有内容:
(?<=\{).*(?=\})
然后你可以用C#去除内部括号:
var regex = new Regex(@"(?<=\{).*(?=\})", RegexOptions.Singleline);
var match = regex.Match(input);
return match.Value.Replace("{", string.Empty).Replace("}", string.Empty);