On Mon, Sep 27, 2010 at 1:34 PM, Titus von der Malsburg
<malsb...@gmail.com> wrote:
> On Mon, Sep 27, 2010 at 7:29 PM, Gabor Grothendieck
> <ggrothendi...@gmail.com> wrote:
>> Try this zero width negative look behind expression:
>>
>>> gregexpr("(?!a+)(b+)", "abcdaabbc", perl = TRUE)
>> [[1]]
>> [1] 2 7
>> attr(,"match.length")
>> [1] 1 2
>
> Thanks Gabor, but this gives me the same result as
>
>  gregexpr("b+", "abcdaabbc", perl = TRUE)
>
> which is wrong if the string is "abcdaabbcbbb".
>

Sorry, try this:

>  gregexpr("(?<=a)b+", "abcdaabbcbbb", perl = TRUE)
[[1]]
[1] 2 7
attr(,"match.length")
[1] 1 2

Note that it does not give the same answer as:

>  gregexpr("b+", "abcdaabbcbbb", perl = TRUE)
[[1]]
[1]  2  7 10
attr(,"match.length")
[1] 1 2 3


 gregexpr("(?<=a)b+", "abcdaabbcbbb", perl = TRUE)




-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@r-project.org 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.

Reply via email to