【发布时间】:2014-11-26 17:24:11
【问题描述】:
我正在尝试从数据集中提取 html 链接。我正在使用 strsplit 然后 grep 来查找带有链接的子字符串,但结果在字符串的开头或结尾都有不需要的字符....如何仅提取具有所需模式的字符串或保留字符串想要的图案
他就是我目前正在做的事情。
1) 我使用 strplit 和 " " (空格) 作为分隔符来分割一段文本
2)接下来我grep strsplit的结果来找到模式
例如grep("https:\/\/support.google.com\/blogger\/topic\/[0-9]",r)
3) 结果的一些变化如下所示....
https://support.google.com/blogger/topic/12457
https://support.google.com/blogger/topic/12457.
[https://support.google.com/blogger/topic/12457]
<<https://support.google.com/blogger/topic/12457>>
https://support.google.com/blogger/topic/12457,
https://support.google.com/blogger/topic/12457),
xxxxxxhttps://support.google.com/blogger/topic/12457),hhhththta
etc...
如何只提取“https://support.google.com/blogger/topic/12457”或提取脏数据后如何删除不需要的标点符号
提前致谢。
【问题讨论】:
-
如果
gsub(".*(http.*\\d).*", "\\1", x)都以数字结尾