Try this:
gsub("^(\\w*).*$", "\\1", x)
On Wed, May 13, 2009 at 8:41 PM, Stephen J. Barr <[email protected]>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 = "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
>
> ______________________________________________
> [email protected] 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.