Friday 31 July 2015

R: regexpr(): Search for a pattern in given text

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

> regexpr("to", "If you haven't got anything nice to say about anybody, come sit next to me.")
[1] 34
attr(,"match.length")
[1] 2
attr(,"useBytes")
[1] TRUE
>
>
> regexpr("If", "If you haven't got anything nice to say about anybody, come sit next to me.", fixed=TRUE)
[1] 1
attr(,"match.length")
[1] 2
attr(,"useBytes")
[1] TRUE
>
> 
> regexpr("got", "If you haven't got anything nice to say about anybody, come sit next to me.", fixed=TRUE)
[1] 16
attr(,"match.length")
[1] 3
attr(,"useBytes")
[1] TRUE


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment