str_view shows the first match; str_view_all shows all the matches.

str_view(string, pattern, match = NA)

str_view_all(string, pattern, match = NA)

Arguments

string

Input vector. Either a character vector, or something coercible to one.

pattern

Pattern to look for.

The default interpretation is a regular expression, as described in stringi-search-regex. Control options with regex().

Match a fixed string (i.e. by comparing only bytes), using fixed(x). This is fast, but approximate. Generally, for matching human text, you'll want coll(x) which respects character matching rules for the specified locale.

Match character, word, line and sentence boundaries with boundary(). An empty pattern, "", is equivalent to boundary("character").

match

If TRUE, shows only strings that match the pattern. If FALSE, shows only the strings that don't match the pattern. Otherwise (the default, NA) displays both matches and non-matches.

Examples

str_view(c("abc", "def", "fgh"), "[aeiou]")
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
str_view(c("abc", "def", "fgh"), "^")
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
str_view(c("abc", "def", "fgh"), "..")
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
# Show all matches with str_view_all str_view_all(c("abc", "def", "fgh"), "d|e")
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
# Use match to control what is shown str_view(c("abc", "def", "fgh"), "d|e")
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
str_view(c("abc", "def", "fgh"), "d|e", match = TRUE)
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected
str_view(c("abc", "def", "fgh"), "d|e", match = FALSE)
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
#> Error in dirname(to): a character vector argument expected