try this:

> x <- c("XXX184_YYY_ZZZ.dat", "YY123_YY_ZZ.dat")
> sub("(^[[:alpha:]]+)[[:digit:]]+.*", "\\1 <file://0.0.0.1/>", x,
perl=TRUE)
[1] "XXX" "YY"
>


On Fri, Mar 26, 2010 at 2:27 PM, arnaud chozo <arnaud.chozo@gmail.com>wrote:

> Hi,
>
> I need to select a substring from the filename of a file in a list.
> I can find all the filenames in a directory by
>
> list.files(fn_dir)
>
> Each filename has the format (the following is an example because field
> lengths are variable)
>
> XXX184_YYY_ZZZ.dat
>
> XXX: 2 or 3 alphabetic characters
> 184: 3 numeric characters
> ...
>
> I'd like to select the substring XXX which has variable length (from each
> filename). I saw regular expressions help but still I can't figure out how
> to do.
>
>
> Thanks,
> Arnaud Chozo
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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<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?

	[[alternative HTML version deleted]]

