R: Perform replacement with 'gsub()' on elements matched from...

grep_sub {xfun} | R Documentation

## 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)

[Package xfun version 0.29 Index]