Rev 71627 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/grepRaw.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2016 R Core Team% Distributed under GPL 2 or later\name{grepRaw}\title{Pattern Matching for Raw Vectors}\alias{grepRaw}\description{\code{grepRaw} searches for substring \code{pattern} matches within araw vector \code{x}.}\usage{grepRaw(pattern, x, offset = 1L, ignore.case = FALSE,value = FALSE, fixed = FALSE, all = FALSE, invert = FALSE)}\arguments{\item{pattern}{raw vector containing a \link{regular expression}(or fixed pattern for \code{fixed = TRUE}) to be matched in thegiven raw vector. Coerced by \code{\link{charToRaw}} to a characterstring if possible.}\item{x}{a raw vector where matches are sought, or an object which canbe coerced by \code{charToRaw} to a raw vector. \link{Long vectors}are not supported.}\item{ignore.case}{if \code{FALSE}, the pattern matching is \emph{casesensitive} and if \code{TRUE}, case is ignored during matching.}\item{offset}{An integer specifying the offset fromwhich the search should start. Must be positive. The beginning ofline is defined to be at that offset so \code{"^"} will match there.}\item{value}{logical. Determines the return value: see \sQuote{Value}.}\item{fixed}{logical. If \code{TRUE}, \code{pattern} is a pattern to bematched as is.}\item{all}{logical. If \code{TRUE} all matches are returned,otherwise just the first one.}\item{invert}{logical. If \code{TRUE} return indices or values forelements that do \emph{not} match. Ignored (with a warning) unless\code{value = TRUE}.}}\details{Unlike \code{\link{grep}}, seeks matching patterns within the rawvector \code{x} . This has implications especially in the \code{all =TRUE} case, e.g., patterns matching empty strings are inherentlyinfinite and thus may lead to unexpected results.The argument \code{invert} is interpreted as asking to return thecomplement of the match, which is only meaningful for \code{value =TRUE}. Argument \code{offset} determines the start of the search, notof the complement. Note that \code{invert = TRUE} with \code{all =TRUE} will split \code{x} into pieces delimited by the patternincluding leading and trailing empty strings (consequently the use ofregular expressions with \code{"^"} or \code{"$"} in that case maylead to less intuitive results).Some combinations of arguments such as \code{fixed = TRUE} with\code{value = TRUE} are supported but are less meaningful.}\value{\code{grepRaw(value = FALSE)} returns an integer vector of the offsetsat which matches have occurred. If \code{all = FALSE} then it will beeither of length zero (no match) or length one (first matchingposition).\code{grepRaw(value = TRUE, all = FALSE)} returns a raw vector whichis either empty (no match) or the matched part of \code{x}.\code{grepRaw(value = TRUE, all = TRUE)} returns a (potentiallyempty) list of raw vectors corresponding to the matched parts.}\source{The TRE library of Ville Laurikari (\url{http://laurikari.net/tre/})is used except for \code{fixed = TRUE}.}% the `aka' below is for ESS\seealso{\link{regular expression} (aka \code{\link{regexp}}) for the detailsof the pattern specification.\code{\link{grep}} for matching character vectors.}\examples{grepRaw("no match", "textText") # integer(0): no matchgrepRaw("adf", "adadfadfdfadadf") # 3 - the first matchgrepRaw("adf", "adadfadfdfadadf", all=TRUE, fixed=TRUE)## [1] 3 6 13 -- three matches}\keyword{utilities}