Currently we can extract (say) a character matrix via capturing groups, using an integer vector to reference groups by position.
library(stringr)
shopping_list <- c("apples x4", "bag of flour", "bag of sugar", "milk x2")
named_regex <- "(?<g1>[a-z]+) of (?<g2>[a-z]+)"
str_extract(shopping_list, named_regex, group = 1:2)
#> g1 g2
#> [1,] NA NA
#> [2,] "bag" "flour"
#> [3,] "bag" "sugar"
#> [4,] NA NA
Created on 2026-05-15 with reprex v2.1.1
It would be nice to reference groups by name, using a character vector.
str_extract(shopping_list, named_regex, group = c("g1", "g2"))
Mixing the two is probably out of scope.
str_extract(shopping_list, named_regex, group = list(1, "g2"))
Currently we can extract (say) a
charactermatrix via capturing groups, using anintegervector to reference groups by position.Created on 2026-05-15 with reprex v2.1.1
It would be nice to reference groups by name, using a
charactervector.Mixing the two is probably out of scope.