ansi_grep: Like 'base::grep()' and 'base::grepl()', but for ANSI strings

View source: R/ansiex.R

ansi_grepR Documentation

Like base::grep() and base::grepl(), but for ANSI strings

Description

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().

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.

Value

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

Examples

red_needle <- col_red("needle")
haystack <- c("foo", "needle", "foo")
green_haystack <- col_green(haystack)
ansi_grepl(red_needle, haystack)
ansi_grepl(red_needle, green_haystack)

cli documentation built on June 22, 2024, 10:57 a.m.