[R] Exact matching with grep
Vladimir Eremeev
wl2776 at gmail.com
Mon Feb 5 15:13:19 CET 2007
Thank you.
There was my misunderstanding of the documentation.
(Un)fortunately, I haven't met the cases, when my code worked incorrectly.
Peter Dalgaard wrote:
>
> Vladimir Eremeev wrote:
>> Mahieux Dimitri wrote:
>>> I would know if it is possible with grep to match a exact string. For
>>> example, I want to match the string "DP2" (and only this) and grep match
>>> "DP2BS" too.
>>> I have sought in the grep help but I didn't find what I want.
>> grep("DP2", {other arguments}, fixed=TRUE)
>>
>> ?grep says that "fixed is logical. If TRUE, pattern is a string to be
>> matched as is. Overrides all conflicting arguments."
>>
> That's not the issue here:
>> grep("DP2", c("DP2","x", "DP2BS","y"))
> [1] 1 3
>> grep("DP2", c("DP2","x", "DP2BS","y"), fixed=TRUE)
> [1] 1 3
>> grep("^DP2$", c("DP2","x", "DP2BS","y"))
> [1] 1
>> which("DP2"==c("DP2","x", "DP2BS","y"))
> [1] 1
>
> "fixed=TRUE" avoids special interpretation of metacharacters, but that
> doesn't solve the problem of matching the entire string.
>
--
View this message in context: http://www.nabble.com/-R--Exact-matching-with-grep-tf3174076.html#a8806901
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list