I need guidance on how to extract the first (or) top directory from a given path. This includes the first slash and the last slash. For example, in the path: "/chemicalemergencies/category/test-page1.html", I need to extract "/chemicalemergencies/" I've used str\_extract and regex to identify the pattern, but the problem is that it is returning ANY match. This is problematic if the URL has duplicate folders. So for example, if the path is "/chemicalemergencies/category/chemicalemergencies/test-page1.html", it will return BOTH the results, when I only need the first one. How do make pattern detect stop after the first match in the string?

```
Sys.time()
#i=4
for (i in 1:nrow(wwwdevurls)) {
  pathextract_wwwdev <- str_extract(wwwdevurls[i,3],"\\/([A-z0-9]+)\\/")
  pathextract_wwwdev.df[i,1] <- pathextract_wwwdev #Load pathextract into pathextract.df
  pathextract_wwwdev.df[i,2] <- wwwdevurls[i,1] #Load CIO into pathextract.df
}
Sys.time()

```