str_view shows the first match; str_view_all shows all the matches. To build regular expressions interactively, check out the RegExplain RStudio addin.

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::stringi-search-regex. Control options with regex().

Match a fixed string (i.e. by comparing only bytes), using fixed(). This is fast, but approximate. Generally, for matching human text, you'll want coll() 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]") str_view(c("abc", "def", "fgh"), "^") str_view(c("abc", "def", "fgh"), "..") # Show all matches with str_view_all str_view_all(c("abc", "def", "fgh"), "d|e") # Use match to control what is shown str_view(c("abc", "def", "fgh"), "d|e") str_view(c("abc", "def", "fgh"), "d|e", match = TRUE) str_view(c("abc", "def", "fgh"), "d|e", match = FALSE)