[R] regular expression question

Greg Snow Greg.Snow at imail.org
Wed Mar 4 18:34:58 CET 2009


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.




More information about the R-help mailing list