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.
--
O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.