R: sf_gsub

sf_gsub {stringfish} | R Documentation

## sf_gsub

### Description

A function that performs pattern substitution

### Usage

    sf_gsub(subject, pattern, replacement, encode_mode = "auto")

### Arguments

`subject` | The subject character vector to search
`pattern` | The pattern to search for
`replacement` | The replacement string
`encode_mode` | The encoding type to use (UTF-8, latin1, bytes, native or auto)

### Details

The function uses the PCRE2 library, which is also used internally by R. However, syntax may be slightly different. E.g.: capture groups: "\1" in R, but "$1" in PCRE2 (as in Perl). The encoding of the output is determined by the pattern (or forced using encode_mode parameter) and encodings should be compatible. E.g: mixing ASCII and UTF-8 is okay, but not UTF-8 and latin1. Note: the order of paramters is switched compared to the 'gsub' base R function, with subject being first. See also: https://www.pcre.org/current/doc/html/pcre2api.html for more documentation on match syntax.

### Value

A stringfish vector of the replacement string

### See Also

gsub

### Examples

    x <- "hello world"
    pattern <- "^hello (.+)"
    replacement <- "goodbye $1"
    sf_gsub(x, pattern, replacement)

[Package stringfish version 0.12.1 Index]