Friday 31 July 2015

R: gregexpr(): Find all occurrences of pattern

It is similar to regexpr(), but it finds all occurrences of given pattern.

Usage
gregexpr(pattern, text, ignore.case = FALSE, perl = FALSE,
         fixed = FALSE, useBytes = FALSE)

pattern : Pattern to be searched
text : It is a character vector, where search performs
ignore.case : If it is true, search is case insensitive, if it is false, then search is case sensitive.
perl : If it is true, then perl compatible regular expressions are used, else not.
useBytes : If TRUE the matching is done byte-by-byte rather than character-by-character.
fixed : logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.
> gregexpr("to", "If you haven't got anything nice to say about anybody, come sit next to me.")
[[1]]
[1] 34 70
attr(,"match.length")
[1] 2 2
attr(,"useBytes")
[1] TRUE
It finds string “to” in two places, one is at 34th position and other is at 70th position.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment