[R] regular expression submatch?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 1 20:22:18 CET 2010


Try this:

> library(gsubfn)
> strapply("hello world", "hello (.*)")[[1]]
[1] "world"


On Mon, Feb 1, 2010 at 1:57 PM, sjaffe <sjaffe at riskspan.com> wrote:
>
> What is the simplest way to extract a matched subexpression?
>
> Eg. in perl you can do
>
> "hello world" =~ m/hello (.*)/
>
> which would return 1(true) and set $1 to the matched subexpression "world".
>
> --
> View this message in context: http://n4.nabble.com/regular-expression-submatch-tp1459146p1459146.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list