[R] Searching within a ch. string

Gabor Grothendieck ggrothendieck at gmail.com
Mon May 11 16:21:47 CEST 2009

The following is TRUE if the indicated string is found:

regexpr("sdhch", "gdfsa-sdhchc-88") > 0

See ?regexpr

Either of the next two will break up a string into words. The
first needs to know the delimiters whereas the second
needs to know the contents:

> strsplit("gdfsa-sdhchc-88", "\\W+")[[1]]
[1] "gdfsa"  "sdhchc" "88"

> library(gsubfn)
> strapply("gdfsa-sdhchc-88", "\\w+", c)[[1]]
[1] "gdfsa"  "sdhchc" "88"

See ?strplit and ?regex and also the gsubfn home page at:
where you can find info on strapply and also further resources
on regular expressions.

On Mon, May 11, 2009 at 10:07 AM, RON70 <ron_michael70 at yahoo.com> wrote:
> Hi all, is there any function to find some words in a character-string? For
> example suppose the string is : "gdfsa-sdhchc-88", now I want to find
> whether this string contains "sdhch". Is there any R function to do that?
> Regards,
> --
> View this message in context: http://www.nabble.com/Searching-within-a-ch.-string-tp23484010p23484010.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