gpt4 book ai didi

r - 从R中的URL中提取参数

转载 作者:行者123 更新时间:2023-12-01 22:08:59 24 4
gpt4 key购买 nike

我想从一批 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com