我正在循环一些带有嵌入文献参考的文本。其中一些是DOI数字,我需要把它们联系起来。
示例案文:
<div>Interesting article here: doi:10.1203/00006450-199305000-00005</div>到目前为止我尝试过的是:
$html = preg_replace("\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![\"&\'<>])[[:graph:]])+)\b", "<a href='https://doi.org/\\0' target='_new'>doi:\\0</a>",$html);这将返回一个空字符串。
我期待着:
<div>Interesting article here: <a href='https://doi.org/10.1203/00006450-199305000-00005' target='_new'>doi:10.1203/00006450-199305000-00005</a></div>我哪里出问题了?
编辑2018-01-30:更新的DOI解析器根据卡特林的答案如下。
发布于 2013-02-13 20:27:35
使用正则表达式测试工具,我找到了一个适用于示例文本的表达式:
$pattern = '(10[.][0-9]{4,}[^\s"/<>]*/[^\s"<>]+)';
$replacement = "<a href='http://dx.doi.org/$0' target='1'>doi:$0</a>";
$html = preg_replace($pattern, $replacement, $html);hth
发布于 2018-01-30 14:47:58
https://stackoverflow.com/questions/14861893
复制相似问题