如何拆分url

如何拆分url,r,R,我想在R中拆分下面的字符串 这里我想拆分URL,只想得到797998的值。我推荐上面的URL建议,但是如果它存储为字符串,则有两个选项: > library('httr') > parse_url('https://bugzilla.mozilla.org/show_bug.cgi?id=797998') $scheme [1] "https" $hostname [1] "bugzilla.mozilla.org" $port NULL $path [1] "show_bu

我想在R中拆分下面的字符串


这里我想拆分URL,只想得到797998的值。

我推荐上面的URL建议,但是如果它存储为字符串,则有两个选项:

> library('httr')
> parse_url('https://bugzilla.mozilla.org/show_bug.cgi?id=797998')
$scheme
[1] "https"

$hostname
[1] "bugzilla.mozilla.org"

$port
NULL

$path
[1] "show_bug.cgi"

$query
$query$id
[1] "797998"


$params
NULL

$fragment
NULL

$username
NULL

$password
NULL

attr(,"class")
[1] "url"
str <- "https://bugzilla.mozilla.org/show_bug.cgi?id=797998"

# If you know it will follow the only '=' in the string
(num <- unlist(strsplit(str, "="))[2])

# If you know that the number is always the last 6 digits
(num <- substr(str, nchar(str)-5, nchar(str)))

# If you know the number always follows the last '=' sign
revstr <- rev(unlist(strsplit(str, NULL)))
index <- which(revstr == "=")
revnum <- revstr[1:(index-1)]
(num <- paste(rev(revnum), collapse = ""))

str如果需要数字,
library(stringr);str_extract(url1,perl(')(?