strMatchAll: Extract components from all matches

View source: R/strMatchAll.R

strMatchAllR Documentation

Extract components from all matches

Description

Uses gregexec() and regmatches() internally.

Usage

strMatchAll(x, pattern, fixed = FALSE)

Arguments

x

character. Character vector. NA values are allowed.

pattern

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

fixed

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

Details

Expands with NA values for match failures, like stringi and stringr.

Value

list. List of character matrix of match groups.

Note

Updated 2023-09-25.

See Also

  • gregexec(), regmatches(), gregexpr().

  • stringi::stri_match_all().

  • stringr::str_match_all().

  • https://stringr.tidyverse.org/articles/from-base.html

Examples

## Regex match.
object <- strMatchAll(
    x = c("a-b", "c-d", "e_f", NA),
    pattern = "^(.+)-(.+)$",
    fixed = FALSE
)
print(object)

## Fixed match.
object <- strMatchAll(
    x = c("a", "aa", "b", "bb"),
    pattern = "a",
    fixed = TRUE
)
print(object)

acidgenomics/acidbase documentation built on Jan. 26, 2024, 4:26 p.m.