Re: [R] Is there a better way to parse strings than this?

From: Chris Howden <chris_at_trickysolutions.com.au>
Date: Tue, 19 Apr 2011 11:36:21 +1000

Thanks for the explanation,

I think I understand it now. So to paraphrase all your explanations

To match "." in a regular expression then the string "\.\.\." needs to be passed to it. This tells it to escape the special meaning of ".". But in order to get the \ into the string being passed to the function I also need to escape its special meaning, so I need to use "\\.\\.\\."

Chris Howden
Founding Partner
Tricky Solutions
Tricky Solutions 4 Tricky Problems
Evidence Based Strategic Development, IP Commercialisation and Innovation, Data Analysis, Modelling and Training
(mobile) 0410 689 945
(fax / office) (+618) 8952 7878
chris_at_trickysolutions.com.au

-----Original Message-----
From: h.wickham_at_gmail.com [mailto:h.wickham_at_gmail.com] On Behalf Of Hadley Wickham
Sent: Friday, 15 April 2011 11:07 AM
To: Chris Howden
Cc: r-help_at_r-project.org
Subject: Re: [R] Is there a better way to parse strings than this?

> I was trying strsplit(string,"\.\.\.") as per the suggestion in Venables
> and Ripleys book to "(use '\.' to match '.')", which is in the Regular
> expressions section.
>
> I noticed that in the suggestions sent to me people used:
> strsplit(test,"\\.\\.\\.")
>
>
> Could anyone please explain why I should have used "\\.\\.\\." rather
than
> "\.\.\."?

Basically,

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
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.
Received on Tue 19 Apr 2011 - 01:39:32 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 Tue 19 Apr 2011 - 03:00:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive