R: Which strings match the patterns?

str_with_patterns {filesstrings} | R Documentation

## Which strings match the patterns?

### Description

Given a character vector of strings and one of patterns (in regular expression), which of the strings match all (or any) of the patterns.

### Usage

    str_with_patterns(strings, patterns, ignore_case = FALSE, any = FALSE)

### Arguments

`strings` | A character vector.
`patterns` | Regular expressions.
`ignore_case` | Do we want to ignore case when matching patterns?
`any` | Set this to `TRUE` if you want to see which strings match any of the patterns and not all (all is the default).

### Details

For huge character vectors, this can be quite slow and you're better off implementing your own solution with `stringr::str_detect()`.

### Value

A character vector of strings matching the patterns.

### Examples

    str_with_patterns(c("abc", "bcd", "cde"), c("b", "c"))
    str_with_patterns(c("abc", "bcd", "cde"), c("b", "c"), any = TRUE)
    str_with_patterns(toupper(c("abc", "bcd", "cde")), c("b", "c"), any = TRUE)
    str_with_patterns(toupper(c("abc", "bcd", "cde")), c("b", "c"), any = TRUE,
                      ignore_case = TRUE)

[Package filesstrings version 2.5.0 Index]