繁体   English   中英

R 编程 - 如何从使用 gregexpr 给出的字符串中提取以下内容?

[英]R programming - How do I extract the following from the string given using gregexpr?

鉴于以下字符串,我如何提取电子邮件地址? 我要提取的电子邮件地址由<>专门括起来写道:

egstring = 'blah blah blah <taylor_swift@gmail.com> wrote: blah blah blah'

以下是我迄今为止所尝试的。

pos = gregexpr('(?<=(\\<))([a-z0-9.]+\\@[a-z0-9.]+)(?=(\\>\\swrote\\:))',egstring,perl=TRUE)[[1]]

我想要达到的目标:

"taylor_swift@gmail.com"

我得到了什么:

[1] -1
attr(,"match.length")
[1] -1
attr(,"useBytes")
[1] TRUE
attr(,"capture.start")

[1,] -1 -1 -1
attr(,"capture.length")

[1,] -1 -1 -1
attr(,"capture.names")
[1] "" "" ""

我无法弄清楚出了什么问题。 :/

使用 gsub() 这有效:

 gsub(".*<(.*)>.*", "\\1", egstring)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM