我想从一批 URL 中删除“destinationId”参数。
如果我有这样的 URL:
https://urlaub.xxx.de/lastminute/europa/zypern-griechenland/?destinationId=45&semcid=de.ub
我将如何提取 45? (destinationId=45)
我试图使用这样的东西,但我无法开始工作:
destinationIdParameter <- sub("[^0-9].*","",sub("*?\\destinationId=","",url))
最佳答案
使用 stringr
你可以这样得到它:
> library(stringr)
> address <- "https://urlaub.xxx.de/lastminute/europa/zypern-griechenland/?destinationId=45&semcid=de.ub"
> str_match(address, "destinationId=(.*?)&")[,2]
[1] "45"
如果(像我一样)您不习惯使用正则表达式,请使用 qdapRegex
包:
> library(qdapRegex)
> address <- "https://urlaub.xxx.de/lastminute/europa/zypern-griechenland/?destinationId=45&semcid=de.ub"
> ex_between(address, "destinationId=", "&")
[[1]]
[1] "45"
关于r - 从R中的URL中提取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49628339/