Skip to contents

Uses gregexpr() and regmatches() internally.

Usage

strExtractAll(x, pattern, fixed = FALSE)

Arguments

x

character. Character vector. NA values are allowed.

pattern

character(1). Regular expression pattern. Evalutes with gregexpr() internally.

fixed

logical(1). If TRUE, pattern is a string to be matched as is. Otherwise, will match by regular expression.

Value

list. List of character vector extractions. Returns character(0L) for match failure, NA_character_ for NA.

Note

Updated 2023-09-25.

See also

Examples

object <- strExtractAll(
    x = c("apples x4", "bag of flour", "bag of sugar", "milk x2", NA),
    pattern = "[a-z]+"
)
print(object)
#> [[1]]
#> [1] "apples" "x"     
#> 
#> [[2]]
#> [1] "bag"   "of"    "flour"
#> 
#> [[3]]
#> [1] "bag"   "of"    "sugar"
#> 
#> [[4]]
#> [1] "milk" "x"   
#> 
#> [[5]]
#> [1] NA
#>