Skip to content
Prev 215707 / 398500 Next

regular expression help to extract specific strings from text

strapply in gsubfn can extract matches based on content which seems to
be what you want:

library(gsubfn)

f <- function(...) sapply(list(...), paste, collapse = ", ")

DF <- data.frame(x,
	Source = strapply(x, "^(\\w+):", c, simplify = f),
	Mentions = strapply(x, "@(\\w+)", c, simplify = f),
	HashTags = strapply(x, "#(\\w+)", c, simplify = f))

DF[DF == ""] <- NA
On Wed, Mar 31, 2010 at 9:20 AM, Tony B <tony.breyal at googlemail.com> wrote: