Is there a better way to parse strings than this?
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, * you want to match . * so the regular expression you need is \. * and the way you represent that in a string in R is \\. Hadley
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/