Gabor Grothendieck wrote:
>
> Try this:
> 
> library(gsubfn)
> pat <- "([[:upper:]][[:lower:]]*) "
> s <- "Aaaa 3 x 0 Bbbb"
> 
> strapply(s, pat, backref =-1)[[1]]
> 
Ok, I think I got it.

For example, if I want to retrieve Aaaa and Bbbb (which
could be any strings) or the numbers 3 and 0, I would do
this:

library(gsubfn)
pat <- "^([a-zA-Z ]+) ([1-9]*[0-9]) x ([1-9]*[0-9]) ([a-zA-Z ]+)$"
s <- "My team 3 x 0 the team from Outer Space"
x <- strapply(s, pat, c)[[1]]

Then x[1] is s, x[2] is "My team", x[3] is "3", x[4] is "0"
and x[5] is "the team from Outer Space".

Thanks.

Alberto Monteiro

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to