From Greg.Snow at intermountainmail.org  Thu Oct 11 11:10:35 2007
From: Greg.Snow at intermountainmail.org (Greg.Snow at intermountainmail.org)
Date: Thu, 11 Oct 2007 11:10:35 +0200 (CEST)
Subject: [Rd] gregexpr (PR#9965)
Message-ID: <20071011091035.A0399283416A@mail.pubhealth.ku.dk>

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

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

> gregexpr("ab(?=3Dab)","ababab",perl=3DTRUE)
[[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.

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

> -----Original Message-----
> From: r-devel-bounces at r-project.org=20
> [mailto:r-devel-bounces at r-project.org] On Behalf Of=20
> 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)
>=20
> Full_Name: Peter Dolan
> Version: 2.5.1
> OS: Windows
> Submission from: (NULL) (128.193.227.43)
>=20
>=20
> gregexpr does not find all matching substrings if the=20
> substrings overlap:
>=20
> > gregexpr("abab","ababab")
> [[1]]
> [1] 1
> attr(,"match.length")
> [1] 4
>=20
> It does work correctly in Version 2.3.1 under linux.
>=20
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>=20



[Rd] gregexpr (PR#9965)
Greg.Snow at intermountainmail.org