Re: [R] matching period with perl regular expression

2009-05-14 Thread Dieter Menne
Gabor Grothendieck gmail.com> writes: > > R interprets backslash to give special meaning to the next character, i.e. > it strips off the backslash and send the following character to gsub > possibly reinterpreting it specially (for example \n is newline). Thus > a backslash will never get to gs

Re: [R] matching period with perl regular expression

2009-05-13 Thread Bill.Venables
-help-boun...@r-project.org] On Behalf Of Stephen J. Barr Sent: Thursday, 14 May 2009 9:42 AM To: r-help@r-project.org Subject: [R] matching period with perl regular expression Hello, I have several strings where I am trying to eliminate the period and everything after the period, using a regu

Re: [R] matching period with perl regular expression

2009-05-13 Thread Ted Harding
On 13-May-09 23:47:41, Henrique Dallazuanna wrote: > Try this: > > gsub("^(\\w*).*$", "\\1", x) Even simpler: x # [1] "wa.w" gsub("\\..*","",x,perl=TRUE) # [1] "wa" x<-"abcde.fghij.klmno" gsub("\\..*","",x,perl=TRUE) # [1] "abcde" (and it doesn't matter whether 'perl' is TRUE or FALSE)

Re: [R] matching period with perl regular expression

2009-05-13 Thread Gabor Grothendieck
R interprets backslash to give special meaning to the next character, i.e. it strips off the backslash and send the following character to gsub possibly reinterpreting it specially (for example \n is newline). Thus a backslash will never get to gsub unless you use a double backslash. Thus we can u

Re: [R] matching period with perl regular expression

2009-05-13 Thread Henrique Dallazuanna
Try this: gsub("^(\\w*).*$", "\\1", x) On Wed, May 13, 2009 at 8:41 PM, Stephen J. Barr wrote: > Hello, > > I have several strings where I am trying to eliminate the period and > everything after the period, using a regular expression. However, I am > having trouble getting this to work. > > > x

[R] matching period with perl regular expression

2009-05-13 Thread Stephen J. Barr
Hello, I have several strings where I am trying to eliminate the period and everything after the period, using a regular expression. However, I am having trouble getting this to work. > x = "wa.w" > gsub(x, "\..*", "", perl=TRUE) [1] "" Warning messages: 1: '\.' is an unrecognized escape in a cha