Re: [R] regular expression for nth character in a string

2011-04-25 Thread Gabor Grothendieck
2011/4/25 Gonçalo Ferraz : > Hi, I have a string > > "InTrouble" > > and want to extract, say, the first two characters: "In" > or the last three: "blee" > or the 3rd, 4th, and 5th: "Trou" > > Is there an easy way of doing this quickly with regular expressions in gsub, > grep or similar? > strapp

Re: [R] regular expression for nth character in a string

2011-04-25 Thread David Winsemius
On Apr 25, 2011, at 6:17 AM, Gonçalo Ferraz wrote: Hi, I have a string "InTrouble" and want to extract, say, the first two characters: "In" or the last three: "blee" or the 3rd, 4th, and 5th: "Trou" Is there an easy way of doing this quickly with regular expressions in gsub, grep or simila

Re: [R] regular expression for nth character in a string

2011-04-25 Thread Jim Lemon
On 04/25/2011 08:17 PM, Gonçalo Ferraz wrote: Hi, I have a string "InTrouble" and want to extract, say, the first two characters: "In" or the last three: "blee" or the 3rd, 4th, and 5th: "Trou" Is there an easy way of doing this quickly with regular expressions in gsub, grep or similar? Hi

Re: [R] regular expression for nth character in a string

2011-04-25 Thread jim holtman
will this do it: > x <- "InTrouble" > sub("^(..).*", "\\1", x) # first two [1] "In" > sub(".*(...)$", "\\1", x) # last three [1] "ble" > sub("^..(...).*", "\\1", x) # 3rd,4th,5th char [1] "Tro" > 2011/4/25 Gonçalo Ferraz : > Hi, I have a string > > "InTrouble" > > and want to extract, say, t

[R] regular expression for nth character in a string

2011-04-25 Thread Gonçalo Ferraz
Hi, I have a string "InTrouble" and want to extract, say, the first two characters: "In" or the last three: "blee" or the 3rd, 4th, and 5th: "Trou" Is there an easy way of doing this quickly with regular expressions in gsub, grep or similar? Thank you for any help. Gonçalo __