Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

grep_sub

Perform replacement with gsub() on elements matched from grep()


Description

This function is a shorthand of gsub(pattern, replacement, grep(pattern, x, value = TRUE)).

Usage

grep_sub(pattern, replacement, x, ...)

Arguments

pattern, replacement, x, ...

Passed to grep() and gsub().

Value

A character vector.

Examples

# find elements that matches 'a[b]+c' and capitalize 'b' with perl regex
xfun::grep_sub("a([b]+)c", "a\\U\\1c", c("abc", "abbbc", "addc", "123"), perl = TRUE)

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.