stri_replace_regex: Replace Occurrences of a Regex Pattern

Description Usage Arguments Details Value See Also Examples

Description

Replaces with the given replacement string every/first/last substring of the input that matches a regular expression

Usage

1
2
3
4
5
stri_replace_all_regex(str, pattern, replacement, opts_regex = list())

stri_replace_first_regex(str, pattern, replacement, opts_regex = list())

stri_replace_last_regex(str, pattern, replacement, opts_regex = list())

Arguments

str

character vector of strings to search in

pattern

character vector of regular expressions

replacement

character vector of strings to replace with, possibly including references to capture groups

opts_regex

a named list as generated with stri_opts_regex

Details

Vectorized over str, pattern, and replacement.

These functions scan the input string for matches of the pattern. Input that is not part of any match is left unchanged; each match is replaced in the result by the replacement string.

The replacement string may contain references to capture groups (in round parentheses). References are of the form $n, where n is the number of the capture group (their numbering starts from 1).

Value

character vector

See Also

Other search_regex: stri_count_regex; stri_detect_regex; stri_extract_all_regex, stri_extract_all_regex, stri_extract_first_regex, stri_extract_first_regex, stri_extract_last_regex, stri_extract_last_regex; stri_locate_all_regex, stri_locate_all_regex, stri_locate_first_regex, stri_locate_first_regex, stri_locate_last_regex, stri_locate_last_regex; stri_match_all_regex, stri_match_all_regex, stri_match_first_regex, stri_match_first_regex, stri_match_last_regex, stri_match_last_regex; stri_opts_regex; stri_split_regex, stri_split_regex; stringi-search-regex; stringi-search

Other search_replace: stri_replace_all_charclass, stri_replace_all_charclass, stri_replace_first_charclass, stri_replace_first_charclass, stri_replace_last_charclass, stri_replace_last_charclass; stri_replace_all_fixed, stri_replace_all_fixed, stri_replace_first_fixed, stri_replace_first_fixed, stri_replace_last_fixed, stri_replace_last_fixed; stri_replace_all; stri_replace_first; stri_replace_last; stri_replace; stringi-search

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
s <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit."
stri_replace_all_regex(s, " .*? ", "#")
stri_replace_all_regex(s, "(el|s)it", "1234")
stri_replace_all_regex('abaca', 'a', c('!', '*'))
stri_replace_all_regex('123|456|789', '(\\p{N}).(\\p{N})', '$2-$1')
stri_replace_all_regex(c("stringi w R","REXAMINE","123"), '( R|R.)', ' r ')

## End(Not run)

Example output

[1] "Lorem#dolor#amet,#adipisicing elit."
[1] "Lorem ipsum dolor 1234 amet, consectetur adipisicing 1234."
[1] "!b!c!" "*b*c*"
[1] "3-1|6-4|9-7"
[1] "stringi w r " " r XAMINE"    "123"         

stringi documentation built on May 2, 2019, 4:54 p.m.