From Greg.Snow at intermountainmail.org  Wed Oct 10 17:48:30 2007
From: Greg.Snow at intermountainmail.org (Greg Snow)
Date: Wed, 10 Oct 2007 09:48:30 -0600
Subject: [Rd] gregexpr (PR#9965)
In-Reply-To: <20071010143544.1B484288008C@mail.pubhealth.ku.dk>
References: <20071010143544.1B484288008C@mail.pubhealth.ku.dk>
Message-ID: <07E228A5BE53C24CAD490193A7381BBBC80D22@LP-EXCHVS07.CO.IHC.COM>

If you want all the matches (including overlaps) then you could try one
of these:

> gregexpr("(?=abab)","ababab",perl=TRUE)
[[1]]
[1] 1 3
attr(,"match.length")
[1] 0 0

> gregexpr("ab(?=ab)","ababab",perl=TRUE)
[[1]]
[1] 1 3
attr(,"match.length")
[1] 2 2

The book "Mastering Regular Expressions" by Jeffrey Friedl has a lot of
detail on the hows and whys of regular expression matching.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of 
> dolanp at science.oregonstate.edu
> Sent: Wednesday, October 10, 2007 8:36 AM
> To: r-devel at stat.math.ethz.ch
> Cc: R-bugs at biostat.ku.dk
> Subject: [Rd] gregexpr (PR#9965)
> 
> Full_Name: Peter Dolan
> Version: 2.5.1
> OS: Windows
> Submission from: (NULL) (128.193.227.43)
> 
> 
> gregexpr does not find all matching substrings if the 
> substrings overlap:
> 
> > gregexpr("abab","ababab")
> [[1]]
> [1] 1
> attr(,"match.length")
> [1] 4
> 
> It does work correctly in Version 2.3.1 under linux.
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] gregexpr (PR#9965)
Greg Snow