strMatch: Extract components from first match

View source: R/strMatch.R

strMatchR Documentation

Extract components from first match

Description

Uses regexec() and regmatches() internally.

Usage

strMatch(x, pattern, fixed = FALSE)

Arguments

x

character. Character vector. NA values are allowed.

pattern

character(1). Regular expression pattern. Evalutes with regexec() 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

matrix. Character matrix of match groups.

Note

Updated 2023-09-25.

See Also

  • regexec(), regmatches(), regexpr().

  • stringi::stri_match_first().

  • stringr::str_match().

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

  • https://bookdown.org/rdpeng/rprogdatascience/regular-expressions.html

  • https://stackoverflow.com/questions/19171715/

  • https://d-rug.github.io/blog/2015/regex.fick

Examples

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

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

acidgenomics/r-acidbase documentation built on Jan. 12, 2024, 3:56 a.m.