Skip to contents

regex match

Usage

reg_match(x, pattern, group = 1)

Arguments

x

vector

pattern

regex pattern

group

regex group, 1 as default. when group=-1, return full matched tibble

Value

vector or tibble

Examples

v <- stringr::str_c("id", 1:3, c("A", "B", "C"))

reg_match(v, "id(\\d+)(\\w)")
#> [1] "1" "2" "3"

reg_match(v, "id(\\d+)(\\w)", group = 2)
#> [1] "A" "B" "C"

reg_match(v, "id(\\d+)(\\w)", group = -1)
#> # A tibble: 3 × 3
#>   match group1 group2
#>   <chr> <chr>  <chr> 
#> 1 id1A  1      A     
#> 2 id2B  2      B     
#> 3 id3C  3      C