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

From: Jim Lemon <>
Date: Mon, 25 Apr 2011 20:36:15 +1000

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 Gonšalo,
You could always try:


Jim mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 25 Apr 2011 - 10:39:46 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 Mon 25 Apr 2011 - 10:50:33 GMT.

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

list of date sections of archive