Skip to content

First ANSI sequences will be stripped with ansi_strip(), both

Usage

ansi_grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE, ...)

ansi_grepl(pattern, x, ...)

Arguments

pattern

Character scalar, regular expression or fixed string (if fixed = TRUE), the pattern to search for. Other objects will be coerced using as.character().

x

Character vector to search in. Other objects will be coerced using as.character().

ignore.case, perl, value

Passed to base::grep().

...

Extra arguments are passed to base::grep() or base::grepl().

Value

The same as base::grep() and base::grepl(), respectively.

Details

Note that these functions work on code points (or bytes if useBytes = TRUE), and not graphemes.

Unlike base::grep() and base::grepl() these functions do not special case factors.

Both pattern and x are converted to UTF-8.

Examples

red_needle <- col_red("needle")
haystack <- c("foo", "needle", "foo")
green_haystack <- col_green(haystack)
ansi_grepl(red_needle, haystack)
#> [1] FALSE  TRUE FALSE
ansi_grepl(red_needle, green_haystack)
#> [1] FALSE  TRUE FALSE