str_detect_replace: Detect and replace values with regex

View source: R/strings.R

str_detect_replaceR Documentation

Detect and replace values with regex

Description

A wrapper for stringr's str_detect so that one can detect strings with a particular pattern and replacement them outright. Vectorized over patterns and replacements.

Usage

str_detect_replace(string, pattern, replacement)

Arguments

string

(chr vector) A character vector.

pattern

(chr vector) Pattern to look for (REGEX).

replacement

(chr vector) A vector of values to replace with.

Value

A character vector.

Examples

str = 1:99 + c(".", ",", ":") #example str vector
str_detect_replace(str, pattern = c("\\.", ",", ":"), replacement = c("dot", "comma", "colon")) #replace by pattern

Deleetdk/kirkegaard documentation built on April 22, 2024, 5:22 p.m.