I have a dataset with URLs that I want to split using a regex. I have created a regex that I belive works, however I am unsure how to implement it in R.

This is my regex:

```
- Domain: ^(.*[\\\/])
- Path:   (\/[0-9].*\?|$)

```

```
# Libraries
library(tidyr) # function separate, extract

# 1. Read data
df = read.csv2(text = "datetime|url
2021-05-29 16:57:09|https://stackoverflow.com/questions/67755241/how-do-i-put-row-data-from-a-database-into-a-php-variable
2021-05-29 16:58:09|https://stackoverflow.com/
2021-05-29 16:59:09|https://stackoverflow.com/hacker
2021-05-29 17:00:09|https://stackoverflow.com/jobs?so_medium=StackOverflow&so_source=SiteNav
2021-05-29 17:01:09|http://www.bbc.co.uk/
2021-05-29 17:02:09|http://www.bbc.com/weather/2643743?day=3",
               sep="|",stringsAsFactors=F, na.strings="unknown");

# 2. Split URL into domain and path
# Domain: ^(.*[\\\/])
# Path:   (\/[0-9].*\?|$)
df <- df %>% extract(url, c("Domain", "Path"), "^(.*[\\\\/])(\\/[0-9].*\\?|$)") # 

df

```

This produces the following:

```
##              datetime                     Domain Path
## 1 2021-05-29 16:57:09                       <NA> <NA>
## 2 2021-05-29 16:58:09 https://stackoverflow.com/     
## 3 2021-05-29 16:59:09                       <NA> <NA>
## 4 2021-05-29 17:00:09                       <NA> <NA>
## 5 2021-05-29 17:01:09     http://www.bbc.co.uk/     
## 6 2021-05-29 17:02:09                       <NA> <NA>

```