With strapplyc
in the gsubfn package, you can do this with a particularly simple regular expression that extracts every line of word characters following " AS "
(If the field can contain characters without words, replace \\w
with the corresponding expression, for example, any char that is not a space or comma: [^ ,]
):
> library(gsubfn) > strapplyc(s, " AS (\\w+)", simplify = toString)[[1]] [1] "field1, field2, field3"
source share