Re: [R] regular expression question

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 01 May 2008 12:40:37 -0400

This is probably what you are looking for:

> x <- "TICKER.GGG.XXXXXX.dat"
> sub("^.*?\\.([^.]+).*", "\\1", x, perl=TRUE)
[1] "GGG"
> x <- "TICKER.GGGabce.XXXXXX.dat"
> sub("^.*?\\.([^.]+).*", "\\1", x, perl=TRUE)
[1] "GGGabce"

On Thu, May 1, 2008 at 12:27 PM, <markleeds_at_verizon.net> wrote:
> 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 but more generally
> the string between the dot after the R in TICKER and the next
> dot. I still don't have a very good understanding of regular expressions
> but I'm trying to get that slowly. thanks.
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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:54:39 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