[R] Regex: workaround for variable length negative lookbehind

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Dec 1 06:20:48 CET 2008


Gabor Grothendieck wrote:
> Try this:
>
>   
>> vec <- c("aaaa", "baaa", "bbaa", "bbba", "baamm", "aa")
>>     
>
>   
>> grep("^(?!(.)\\1{1,}$).*(.)\\2{1,}$", vec, perl = TRUE)
>>     

or even

grep("^(?!(.)\\1+$).*(.)\\2+$", vec, perl = TRUE)


vQ



More information about the R-help mailing list