Re: [Rd] gregexpr (PR#9965)

From: Greg Snow <Greg.Snow_at_intermountainmail.org>
Date: Wed, 10 Oct 2007 09:48:30 -0600

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
>
______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 10 Oct 2007 - 16:01:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.