grepRaw
Pattern Matching for Raw Vectors

Description

Searches for a raw pattern in a raw vector.

Usage

grepRaw(pattern, x, offset = 1L, ignore.case = FALSE, value = FALSE,
        fixed = FALSE, all = FALSE, invert = FALSE)

Arguments

pattern a raw vector specifying the pattern to search for. If this is not a raw vector, it is coerced with charToRaw(as.character(pattern)).
x a raw vector in which to search. If this is not a raw vector, it is coerced with charToRaw(as.character(x)).
offset a positive integer specifying the byte number in pattern where the search should be started.
ignore.case a logical value. If TRUE, letter case is ignored during matching. If FALSE (the default), the case is not ignored during matching.
value a logical value. If TRUE, the matched raw vector or a list of raw vectors is returned. If FALSE (the default), an integer vector of matched offsets is returned. If value is FALSE, invert=TRUE is ignored (with a warning).
fixed a logical value. If TRUE, the pattern is interpreted as a literal sequence of bytes to match. If FALSE (the default), the pattern is interpreted as a regular expression. If fixed is TRUE, ignore.case=TRUE is ignored (with a warning).
all a logical value. If TRUE, all matches are returned. If FALSE (the default), only the first match is returned.
invert a logical value. If TRUE, return items that do not match the pattern. If FALSE (the default), return the items that match the patten.

Details

Unlike grep, grepRaw searches for matches of a raw pattern in a raw vector. It uses the TRE library (see agrep) from http://laurikari.net/tre for pattern matching.
Value
See Also
grep, agrep
Examples
grepRaw("live", "a live b") # returns the matched offset
grepRaw("live", "a live b", fixed = TRUE) # returns the matched offset
grepRaw("live", "a live b", value = TRUE) # returns the matched raw vector
grepRaw("live", "a live b", value = TRUE, invert = TRUE) # returns the un-matched raw vector
grepRaw("live", "a live b", all = TRUE, value = TRUE) #  returns the matched list of raw vectors

grepRaw("b$", "a live b") # returns the matched offset.

grepRaw("live", "a live b" , offset = 4) # no matching. returns empty integer(0) grepRaw("live", "a live b" , offset = 4, value = TRUE) # no matching. returns empty raw(0) grepRaw("live", "a live b" , offset = 4, value = TRUE, all = TRUE) # no matching. returns empty list()

grepRaw("love", "a LOVE b") # no matching grepRaw("love", "a LOVE b", ignore.case = TRUE) # returns the matched offset

grepRaw("love", "a LOVE b", fixed = TRUE) # no matching grepRaw("love", "a LOVE b", fixed = TRUE, ignore.case = TRUE) # no matching with a warning message: argument "ignore.case = TRUE" will be ignored

grepRaw("live", "a live b", invert = TRUE) # returns the matched offset with warning message: argument "invert = TRUE" will be ignored.

Package base version 6.1.1-7
Package Index