[R] perl expression question

jim holtman jholtman at gmail.com
Tue Aug 12 22:35:45 CEST 2008


Will this do it:

> fileName<-"Agg.20.20.20-all-01"
> sub(".*\\.(\\d+\\.\\d+\\.\\d+).*", "\\1", fileName, perl=TRUE)
[1] "20.20.20"
> sub(".*-([^-]+)-.*", "\\1", fileName, perl=TRUE)
[1] "all"
>


On Tue, Aug 12, 2008 at 4:18 PM,  <markleeds at verizon.net> wrote:
> I have a string such as
>
> fileName<-"Agg.20.20.20-all-01".
>
> All I want to do is pull the "20.20.20" and the "all" as strings.
>
> Obviously, they aren't always those values.
>
> The "20.20.20" can be "30.30.30" but it's always after the . which is next
> to the second g in Agg and it's always the same length. The all might not
> always be "all" but in general  it is the text between the two dashes.
>
> I made an attempt using below but perl expressions and myself are an
> extremely bad match ( pun was intended ) and all I got back was the same
> string as
> fileName in both cases.
>
>  weights=sub("^Agg.(\\.*)-\\.*$", "\1",fileName)
>  dashesstring=sub("^Agg.\\.*-(\\.*)-\\.*$", "\1",fileName)
>
> I could possibly using strsplit but I'm trying to learn perl expressions as
> best I can so a solution using that approach is really appreciated. 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 that you are trying to solve?



More information about the R-help mailing list