Re: [R] regular expression question

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 04 Mar 2009 10:34:58 -0700

Here is another approach that still uses strspit if you want to stay with that:

> tmp <- '(-0.791,-0.263].(-38,-1.24].(0.96,2.43]'
> strsplit(tmp, '\\.(?=\\()', perl=TRUE)
[[1]]
[1] "(-0.791,-0.263]" "(-38,-1.24]" "(0.96,2.43]"

This uses the Perl 'look-ahead' indicator to say only match on a period that is followed by a '(', but don't include the '(' in the match.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
801.408.8111



> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of markleeds_at_verizon.net
> Sent: Monday, March 02, 2009 11:17 PM
> To: r-help_at_r-project.org
> Subject: [R] regular expression question
>
> can someone show me how to use a regular expression to break the string
> at the bottom up into its three components :
>
> (-0.791,-0.263]
> (-38,-1.24]
> (0.96,2.43]
>
> I tried to use strplit because of my regexpitis ( it's not curable.
> i've
> been to many doctors all over NYC. they tell me there's no cure ) but
> it doesn't work because there also dots inside the brackets. Thanks.
>
> (-0.791,-0.263].(-38,-1.24].(0.96,2.43]
>
> ______________________________________________
> R-help_at_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.
______________________________________________ R-help_at_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.
Received on Wed 04 Mar 2009 - 16:37:14 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 Wed 04 Mar 2009 - 17:30:23 GMT.

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

list of date sections of archive