If a string contains a given pattern duplicated back-to-back a number of times, remove that duplication, leaving the pattern appearing once in that position (works if the pattern is duplicated in different parts of a string, removing all instances of duplication). This is vectorized over string and pattern.

str_singleize(string, pattern)

Arguments

string

A character vector.

pattern

The pattern to look for.

The default interpretation is a regular expression, as described in stringi::about_search_regex.

To match a without regular expression (i.e. as a human would), use coll(). For details see stringr::regex().

Value

A character vector.

See also

Examples

str_singleize("abc//def", "/")
#> [1] "abc/def"
str_singleize("abababcabab", "ab")
#> [1] "abcab"
str_singleize(c("abab", "cdcd"), "cd")
#> [1] "abab" "cd"  
str_singleize(c("abab", "cdcd"), c("ab", "cd"))
#> [1] "ab" "cd"