string_replace: Replace matched patterns in a string

View source: R/string.R

string_replaceR Documentation

Replace matched patterns in a string

Description

Vectorised pattern replacement using Perl-compatible regular expressions.

Usage

string_replace(string, pattern, replacement)

string_replace_all(string, pattern, ignore_case = FALSE)

Arguments

string

A character vector.

pattern

Pattern to look for. A single element vector if string_replace or a named vector of patterns and replacements if string_replace_all.

replacement

A character vector of replacement. Only applies to string_replace.

ignore_case

Should letter case be ignored? Only applies to string_replace_all.

Value

A character vector.

Examples

string_replace("10meters", "\\d+\\K", " ")

patterns <- c("_" = " ", "\\pS" = "")
string_replace_all("L'Aigle_et_le_HibouĀ®", patterns)

arnaudgallou/toolkit documentation built on Nov. 25, 2022, 5:42 p.m.