解析Bibtex文件 [英] Parse Bibtex files

查看:317
本文介绍了解析Bibtex文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用php或javascript解析以下 bibtex 字符串或整个 .bib 文件。

I would like to parse the following bibtex string or maybe a whole .bib file using php or javascript.

有任何建议吗?

字符串如下:

@article{Sng:2010:PMW:1750585.1750678,
 author = {Sng, Colin T. S. and Manlove, David F.},
 title = {Popular matchings in the weighted capacitated house allocation problem},
 journal = {J. of Discrete Algorithms},
 issue_date = {June, 2010},
 volume = {8},
 number = {2},
 month = jun,
 year = {2010},
 issn = {1570-8667},
 pages = {102--116},
 numpages = {15},
 url = {http://dx.doi.org/10.1016/j.jda.2008.11.008},
 doi = {10.1016/j.jda.2008.11.008},
 acmid = {1750678},
 publisher = {Elsevier Science Publishers B. V.},
 address = {Amsterdam, The Netherlands, The Netherlands},
 keywords = {Maximum popular matching, Polynomial-time algorithm, Popular matching     problem, Priorities, Strict preference lists},
} 


推荐答案

我不能非常记得BibTeX语法,但我建议转换语法,使其可以通过 JSON.parse 进行解析,如下所示:

I can't quite remember the BibTeX syntax, but I'd suggest to convert the syntax to make it parsable by JSON.parse, like this:

var bibjson = bibtex.replace(/(\w+)\s*=\s*\{/g,"\"$1\": \"")
          .replace(/\}(?=\s*[,\}])/g,"\"")
          .replace(/@(\w+)\s*\{([^,]*)/,"{\"$1\": \"$2\"");
var bibobj = JSON.parse(bibjson);

这篇关于解析Bibtex文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆