Jiu*_*Guo 3 regex string r regex-greedy regex-lookarounds
我有一份参考文献清单,例如
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."
)
Run Code Online (Sandbox Code Playgroud)
我尝试过,(?<=:)(?.*)(?=(v\.)|(no\.)|(p\.))但是正则表达式从大陆组装返回到大陆内部变形:《梦幻岛杂志》第3版,否。第192页。不是我打算提取的。
(?<=:)(?:[^:].*?)(?=(, v\.)|(, no\.)|(, p\.))
Run Code Online (Sandbox Code Playgroud)
我期望的是《梦幻岛日记》,但返回的是《从大陆组装到洲际变形:梦幻岛日记》
在这里,我们只将最后一个冒号之前的文本与捕获组中的下一个逗号匹配
stringr::str_match(references, ": ((?!:)[^,:]*),")[,2]
# [1] "Journal of Neverland" "Journal of Neverland" "Journal of Neverland"
Run Code Online (Sandbox Code Playgroud)