Skip to content
Prev 112353 / 398500 Next

Help with grep (and similar functions)

Try this:

library(gsubfn)
pat <- "([[:upper:]][[:lower:]]*) "
s <- "Aaaa 3 x 0 Bbbb"

strapply(s, pat, backref =-1)[[1]]

or (not quite as general but works in this case):

pat <- "([[:upper:]][[:lower:]]*) "
s <- "Aaaa 3 x 0 Bbbb"

s.idx <- gregexpr(pat, s)[[1]]
substring(s, s.idx, s.idx + attr(s.idx, "match.length") - 2)
On 3/28/07, Alberto Monteiro <albmont at centroin.com.br> wrote: