I'm struggling to find the best solution to extract multiple urls from a (very long) string.
Here's an example text:
miserie <- "some text /Home/123/home-name/Specs some other text http://www.example.com/Specs some other text /Home/456/home-name/Specs"
Edit: Updated example:
miserie <- "/Home/homes?query=123 qdf /Home/123/home-name/Specs , homeurl : http://www.example.com/ },{ id :1, y : 02 , p :false, url : /Home/456/home-name/Specs"
This is the outcome I want:
[1] "/Home/123/home-name/Specs"
[2] "/Home/456/home-name/Specs"
In essence, I need a solid solution that extract all paths that start with "/Home" and end with "/Specs".
I've tried the following pattern:
pat <- ".*(/Home/.*/Specs).*"
And the following functions:
str_match_all(miserie,pat)
gsub(x=miserie, pattern=pat, replace="\\1")
The first returned this result:
[[1]]
[,1]
[1,] "some text /Home/123/home-name/Specs some other text http://www.example.com/Speccs some other text /Home/456/home-name/Specs"
[,2]
[1,] "/Home/456/home-name/Specs"
And the second only returned the last URL:
[1] "/Home/456/home-name/Specs"
Any suggestions?
/Homeand ending in/Specs? Or, might you also want to capture other types of paths?