Re: [R] Regular Expressions Help

From: Hans-Jörg Bibiko <>
Date: Sat, 19 Apr 2008 13:51:04 +0200

On 19.04.2008, at 06:46, maud wrote:

> I am having some trouble learning regular expressions. Let me describe
> the general problem I am dealing with. Consider the following setup:
> Joe<- c(1,2,3)
> Bob<- c(2,4,6)
> Alice <- c(9,8,7)
> Matrix <- cbind(Joe, Bob, Alice)
> St <- c("Bob", "Alice", "Alice:Bob")
> [...]
> I have been reading over various post on regular expressions, but
> really haven't made any progress. As far as I can tell there aren't
> standard string functions in R. (Also, as an aside, is there a
> wildcard character in R? I'd want something so if x="Bob" a statment
> of the form x== "B*b" would evaluate true where * is the wildcard.)

I'm not really sure if I understood you correctly. If you're looking for a way to match St against something like "B*b" you can make usage of normal regular expressions (like grep()).

For details begin with ?regexp and ?grep

Then you can try for instance:

grep("B.b", St)

to get
[1] 1 3

(the indices of the vector St)

or directly

St[grep("B.b", St)]

--Hans mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 19 Apr 2008 - 11:55:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 19 Apr 2008 - 12:30:29 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive