stringi (version 0.2-5)

stri_replace_all_charclass: Replace Occurrences of a Character Class

Description

Replaces with a replacement string every/first/last the characters that fall into a class specified by pattern.

Usage

stri_replace_all_charclass(str, pattern, replacement, merge = FALSE)

stri_replace_first_charclass(str, pattern, replacement)

stri_replace_last_charclass(str, pattern, replacement)

Arguments

str
character vector with strings to search in
pattern
character vector specifying character classes to match, see stringi-search-charclass
replacement
character vector of strings to replace with
merge
logical [stri_replace_all_charclass only]; should consecutive matches be merged into a single one?

Value

  • Each function returns a character vector.

Details

Vectorized over str, pattern, and replacement.

These functions scan the input string for matches of a character class. Input that is not part of any match is left unchanged; each match is replaced in the result by the same (fixed) replacement string.

See Also

Other search_charclass: stri_count_charclass; stri_detect_charclass; stri_extract_all_charclass, stri_extract_first_charclass, stri_extract_first_charclass, stri_extract_last_charclass, stri_extract_last_charclass; stri_locate_all_charclass, stri_locate_first_charclass, stri_locate_first_charclass, stri_locate_last_charclass, stri_locate_last_charclass; stri_split_charclass; stri_trim, stri_trim, stri_trim_both, stri_trim_left, stri_trim_right; stringi-search-charclass; stringi-search

Other search_replace: stri_replace_all_coll, stri_replace_first_coll, stri_replace_first_coll, stri_replace_last_coll, stri_replace_last_coll; stri_replace_all_fixed, stri_replace_first_fixed, stri_replace_first_fixed, stri_replace_last_fixed, stri_replace_last_fixed; stri_replace_all_regex, stri_replace_first_regex, stri_replace_first_regex, stri_replace_last_regex, stri_replace_last_regex; stri_replace_all; stri_replace_first; stri_replace_last; stri_replace_na; stri_replace; stringi-search

Examples

Run this code
if (stri_install_check(silent=TRUE))
stri_replace_all_charclass("a\nb\tc   d", "\\p{WHITE_SPACE}", "")

if (stri_install_check(silent=TRUE))
stri_replace_all_charclass("a\nb\tc   d", "\\p{WHITE_SPACE}", "", TRUE)

Run the code above in your browser using DataLab