multi_match: Multiple pattern matching

View source: R/multi_match.R

multi_matchR Documentation

Multiple pattern matching

Description

Match a character vector on multiple patterns.

Usage

multi_match(
  strings,
  patterns,
  replacements,
  ignore_case = TRUE,
  compress = TRUE,
  first = TRUE
)

Arguments

strings

A vector of string to be matched

patterns

A vector of patterns to match

replacements

Replacement label vector of the same length as patterns. If missing, patterns is used.

ignore_case

Should case be ignored in regular expression matching?

compress

If TRUE, returns the first matched pattern (or label). Otherwise, returns a tibble of matches for each pattern

first

If TRUE, then the first match is returned otherwise the last is returned. This is ignored if compress = FALSE.

Value

If compress = TRUE, returns a character vector. Otherwise, returns a tibble.

Author(s)

Sven Halvorson

Examples

strings = c('abcde', 'bc', 'def', 'gjab', 'xyz')
patterns = c('ab', 'de', 'bc')
replacements = toupper(patterns)

# Find the first match of each pattern:
multi_match(
  string = strings,
  patterns = patterns,
  replacements = replacements
)

# Make flags for matching each pattern:
multi_match(
  strings = strings,
  patterns = patterns,
  compress = FALSE
)


svenhalvorson/SvenR documentation built on Aug. 25, 2023, 1:31 p.m.