[R] matching period with perl regular expression

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu May 14 01:59:13 CEST 2009


You have the arguments out of line and you need two backslashes:

> x <- "wa.w"
> gsub("\\..*", "", x)
[1] "wa"
>  


Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Stephen J. Barr
Sent: Thursday, 14 May 2009 9:42 AM
To: r-help at 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 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 character string
2: unrecognized escape removed from "\..*"

In perl, you can match a single period with \.
Is this not so even with perl=TRUE. I would like for x to be equal to
> x = "wa"

What am I missing here?
-stephen
==========================================
Stephen J. Barr
University of Washington
WEB: www.econsteve.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