how to clean a query string in a URL?

ℕʘʘ*_*ḆḽḘ 0 regex url r stringr

Consider this simple example

www.stackunderflow.com?q=snack%20over%20flow

I am interested in parsing the query string of the url. However, as you can see, I have these annoying URL encoding strings (such as %20) that I need convert.

How can I do that in R? I would like to obtain a clean string such as snack over flow. I know how to get the query part :

> str_match('www.stackunderflow.com?q=snack%20over%20flow', regex('\\?q=(.*)'))[,2]
[1] "snack%20over%20flow"
Run Code Online (Sandbox Code Playgroud)

but I dont know how to clean the string.

Thanks!

Arc*_*tte 6

我发现urltools包在这里有用

# install.packages("urltools")
library(urltools)
url_decode("snack%20over%20flow")
#[1] "snack over flow"
Run Code Online (Sandbox Code Playgroud)