嵌套大括号内数据的Regex
本文关键字:数据 Regex 嵌套 | 更新日期: 2023-09-27 18:21:21
我有以下数据记录:
@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 = ".*[{].*}";
这个正则表达式在Singleline模式下,将获取两个外部大括号内的所有内容:
(?<='{).*(?='})
然后你可以用C#去掉内部支架:
var regex = new Regex(@"(?<='{).*(?='})", RegexOptions.Singleline);
var match = regex.Match(input);
return match.Value.Replace("{", string.Empty).Replace("}", string.Empty);