gpt4 book ai didi

R命令在包含大括号的两个字符串之间提取文本

转载 作者:行者123 更新时间:2023-12-05 01:04:46 26 4
gpt4 key购买 nike

我正在尝试使用 stringr 库中的 R str_match 函数来提取书目条目中的标题,如下所示。确实,我需要提取
之间的文字"title={"和 "}," 字符串。

a2
[1] "@article{2020, title={Long noncoding RNA MEG3 decreases the growth of head and neck squamous cell carcinoma by regulating the expression of miR‐421 and E‐cadherin}, volume={9}, ISSN={2045-7634}, url={http://dx.doi.org/10.1002/cam4.3002}, DOI={10.1002/cam4.3002}, number={11}, journal={Cancer Medicine}, publisher={Wiley}, author={Ji, Yefeng and Feng, Guanying and Hou, Yunwen and Yu, Yang and Wang, Ruixia and Yuan, Hua}, year={2020}, month={Apr}, pages={3954–3963} }"

我使用了以下方法,但收到一条错误消息:

str_match(a2, "(?s)title={\\s*(.*?)\\s*},.")

Error in stri_match_first_regex(string, pattern, opts_regex = opts(pattern)) :
Error in {min,max} interval. (U_REGEX_BAD_INTERVAL, context=(?s)title={\s*(.*?)\s*},.)

我想问题出在大括号的匹配上,但我无法取得任何进展。任何指针将不胜感激。

最佳答案

既然你想解析一个bibtex文件,你可以做的是使用bib2df::bib2dfreference.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"

关于R命令在包含大括号的两个字符串之间提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71536832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com