Message-ID: <49AEBF1C.1080007@idi.ntnu.no>
Date: 2009-03-04T17:49:16Z
From: Wacek Kusnierczyk
Subject: regular expression question
In-Reply-To: <B37C0A15B8FB3C468B5BC7EBC7DA14CC61CC034357@LP-EXMBVS10.CO.IHC.COM>
Greg Snow wrote:
> Here is another approach that still uses strspit if you want to stay with that:
>
>
>> tmp <- '(-0.791,-0.263].(-38,-1.24].(0.96,2.43]'
>> strsplit(tmp, '\\.(?=\\()', perl=TRUE)
>>
> [[1]]
> [1] "(-0.791,-0.263]" "(-38,-1.24]" "(0.96,2.43]"
>
> This uses the Perl 'look-ahead' indicator to say only match on a period that is followed by a '(', but don't include the '(' in the match.
>
right; you could extend this pattern to split the string by every dot
that does not separate two digits, for example:
strsplit(tmp, '(?<!\\d)\\.(?!\\d)', perl=TRUE)
of course, this fails if there are numbers without a leading zero, e.g., .11
vQ