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

标签 r regex substring gsub

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

相关文章:

RStudio-如何生成内联 r 结果?

swift 4 : Cannot subscript a value of type 'String' with an index of type 'CountablePartialRangeFrom<Int>'

r - R file.mtime()在Mac OS和Windows 7上的精度极差

r - 条形图 dplyr 汇总值

java - 正则表达式用空格拆分包含标签但不破坏 java 中的标签的字符串

php - 清理/替换所有日语、中文、韩语、俄语等字符

java - 如何使用交替来匹配正则表达式中的最长匹配项?

mysql - 选择字符串中除第一个字符以外的所有字符

c# - 这段代码怎么可能: "ArgumentOutOfRangeException: startIndex cannot be larger than length of string"?

R:如何去除字符串中的问号 block ?