Uses gregexec() and regmatches() internally.
Arguments
- x
character. Character vector.NAvalues are allowed.- pattern
character(1). Regular expression pattern. Evalutes withgregexec()internally.- fixed
logical(1). IfTRUE,patternis a string to be matched as is. Otherwise, will match by regular expression.
Examples
## Regex match.
object <- strMatchAll(
x = c("a-b", "c-d", "e_f", NA),
pattern = "^(.+)-(.+)$",
fixed = FALSE
)
print(object)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] "a-b" "a" "b"
#>
#> [[2]]
#> [,1] [,2] [,3]
#> [1,] "c-d" "c" "d"
#>
#> [[3]]
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#>
#> [[4]]
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#>
## Fixed match.
object <- strMatchAll(
x = c("a", "aa", "b", "bb"),
pattern = "a",
fixed = TRUE
)
print(object)
#> [[1]]
#> [,1]
#> [1,] "a"
#>
#> [[2]]
#> [,1]
#> [1,] "a"
#> [2,] "a"
#>
#> [[3]]
#> [,1]
#> [1,] NA
#>
#> [[4]]
#> [,1]
#> [1,] NA
#>