Extract URL parameters and values in R
问题 We want to extract parameters and values from a given URL like http://www.exemple.com/?a=1&b=2&c=3#def Using xml2::url_parse we were able to Parse a url into its component pieces. However we still want to devide the query into elements using gsub matching regular expression: ([^?&=#]+)=([^&#]*) Desired output a=1 b=2 c=3 回答1: We can try library(stringr) matrix(str_extract_all(str1, "[a-z](?=\\=)|(?<=\\=)\\d+")[[1]], ncol=2, byrow=TRUE) Or if we need the = also str_extract_all(str1, "[a-z]=\\d