Re: [R] regular expression question

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Thu, 01 May 2008 10:11:23 -0700

  1. Yes. strsplit(yourstring,"\\.")[[1:2]] works if the format is as specified below.
  2. In Jim Holtman's regex, the PERL=TRUE argument is not needed.

sub("TICKER\\.([^.]+).*","\\1",x)

works just fine.

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Johannes Hüsing
Sent: Thursday, May 01, 2008 9:45 AM
To: r-help_at_r-project.org
Subject: Re: [R] regular expression question

markleeds_at_verizon.net <markleeds_at_verizon.net> [Thu, May 01, 2008 at 06:27:15PM CEST]:
> I have strings of the form
>
> TICKER.GGG.XXXXXX.dat
>
> but GGG is not always three characters so I can't use substr to pull it
> out of the string.
>
> Could someone tell me how to use sub to pull out the GGG

Doesn't strsplit() help you more easily here?

-- 
Johannes Hsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes_at_huesing.name  from such a trifling investment of fact.

http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")

______________________________________________
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 Thu 01 May 2008 - 17:58:03 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 01 May 2008 - 18:30:33 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