r - 如何将引用列表转换为数据框?

标签 r regex string regex-lookarounds regex-greedy

我有一个引用列表,例如,

references <- c(
  "Dumitru, T.A., Smith, D., Chang, E.Z., and Graham, S.A., 2001, Uplift, exhumation, and deformation in the Japanese Mt Everest, Paleozoic and Mesozoic tectonic evolution of central Africa: from continental assembly to intracontinental deformation: Journal of Neverland, v. 3, no. 192, p. 71-199.",
  "Dumitru, T.A., Smith, D., Chang, E.Z., and Graham, S.A., 2001, Uplift, exhumation, and deformation in the Japanese Mt Everest, Paleozoic and Mesozoic tectonic evolution of central Africa: from continental assembly to intracontinental deformation: Journal of Neverland, no. 3.",
  "Dumitru, T.A., Smith, D., Chang, E.Z., and Graham, S.A., 2001, Uplift, exhumation, and deformation in the Japanese Mt Everest, Paleozoic and Mesozoic tectonic evolution of central Africa: from continental assembly to intracontinental deformation: Journal of Neverland, p. 71-199."
)

我试过 (?<=:)(?.*)(?=(v\.)|(no\.)|(p\.))但正则表达式返回“从大陆组装到陆内变形:梦幻岛杂志,v. 3, no。 192,页。不是我打算提取的。

(?<=:)(?:[^:].*?)(?=(, v\.)|(, no\.)|(, p\.))

我期待的是“梦幻岛日志”,但回归是“从大陆组装到大陆内变形:梦幻岛日志”

最佳答案

这里我们只是匹配捕获组中最后一个冒号之前的文本到下一个逗号

stringr::str_match(references, ": ((?!:)[^,:]*),")[,2]
# [1] "Journal of Neverland" "Journal of Neverland" "Journal of Neverland"

关于r - 如何将引用列表转换为数据框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56245545/

相关文章:

r - 生成独特的数字模式(例如,1221 被视为与 2112 相同的模式)

从列表列表中删除 NA

javascript - 正则表达式负向预测不包括整个 block

c++ - 动态数组和字符串出现问题 (C++)

r - 检查一个变量 R 中各种 DATE 的差异

r - 在 j 表达式中再次使用函数结果

Python:使用正则表达式捕获模式中的子模式

c# - 组的可选正则表达式匹配不起作用

C - 字符数组似乎可以复制,但仅限于循环范围内

java - 将 textView 转换为字符串