我试图使用字符串库中的R str_match函数来提取书目条目中的标题,如下所示。实际上,我需要提取
"title={" and the "},"字符串。
a2 1“@{2020,title={长非编码RNA MEG3 )通过调节miR-421和publisher=}、volume={9}、ISSN={2045-7634}、url={http://dx.doi.org/10.1002/cam4.3002}、DOI={10.1002/cam4.3002}、number={11}、journal={癌医学}、publisher={Wiley}、author={Ji、叶峰和冯、冠英和侯、云文、余、杨和王、瑞霞和袁、华}、华}、罗布里( month={Apr}、pages={3954-3963}}的表达,降低头颈部鳞状细胞癌的生长。”
我使用了如下方法,但是我得到了一个错误消息:
str_match(a2, "(?s)title={\\s*(.*?)\\s*},.")Stri_match_first_regex中的错误(字符串、模式、opts_regex =opts(模式)): 在{min,max}间隔内出错。(U_REGEX_BAD_INTERVAL,context=
(?s)title={\s*(.*?)\s*},.)
我想问题是与圆括号的匹配,但我无法取得任何进展。任何指针都将不胜感激。
发布于 2022-03-19 11:04:32
因为您想解析一个bibtex文件,所以您可以使用bib2df::bib2df,reference.bib是您的bibtex文件。
install.packages("bib2df")
library(bib2df)
bib2df("reference.bib")$TITLE..LONG
# [1] "Long noncoding RNA MEG3 decreases the growth of head and neck squamous cell carcinoma by regulating the expression of miR-421 and E-cadherin"发布于 2022-03-19 10:06:37
基于stringr::str_extract的另一种可能的解决方案
library(tidyverse)
a2 %>%
str_extract("(?<=title\\=\\{)[^\\}]*(?=\\},)")
#> [1] "Long noncoding RNA MEG3 decreases the growth of head and neck squamous cell carcinoma by regulating the expression of miR‐421 and E‐cadherin"https://stackoverflow.com/questions/71536832
复制相似问题