[R] using sub with "wildcards", e.g. sub("\\*..", "", "test.a..34")

Charilaos Skiadas cskiadas at gmail.com
Wed Jan 9 00:08:55 CET 2008


If this is really the case you are dealing with, wouldn't strsplit do  
the job more easily?

On Jan 8, 2008, at 5:47 PM, Thomas Pujol wrote:

> I have a text string "test.a..34"
>
>   I wish to extract the text that comes after ".." (e.g. "34"), and  
> the text that comes before ".." (e.g. "test.a").
>
>   What is a good way to do this? Also, can you help me understand  
> how to use "wildcards" such as "*" with sub, etc?
>
>
>   #This seems to work, but I am unclear how it works:
>   sub("\\*..", "", "test.a..34")
>
>   #This does not work:
>   sub("\\*..", "", "test.a..34")
>
Those two lines look the same to me, and they don't work.
Perhaps you wanted:  sub("\\.\\.", "", "test.a..34")

Have you looked at ?regex  ?

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College




More information about the R-help mailing list