[R] Do grep() and strsplit() use different regex engines?
Bert Gunter
bgunter.4567 at gmail.com
Sat Jul 11 18:19:47 CEST 2015
Thanks Jeff. That doesn't explain it for me. Could you go through the
algorithm a step at a time to show why it splits at the individual
characters rather than the words, perhaps privately. Feel free to
refuse, as I'm sure you have better things to do.
-- Bert
Bert Gunter
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
-- Clifford Stoll
On Sat, Jul 11, 2015 at 8:52 AM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> "\\b" is a zero length match. strsplit seems to chop at least one character off the beginning of the string if it sees a match, and then it looks at the shortened string that remains and repeats.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On July 11, 2015 7:47:22 AM PDT, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>>I noticed the following:
>>
>>> strsplit("red green","\\b")
>>[[1]]
>>[1] "r" "e" "d" " " "g" "r" "e" "e" "n"
>>
>>> strsplit("red green","\\W")
>>[[1]]
>>[1] "red" "green"
>>
>>I would have thought that "\\b" should give what "\\W" did. Note that:
>>
>>> grep("\\bred\\b","red green")
>>[1] 1
>>## as expected
>>
>>Does strsplit use a different regex engine than grep()? Or more
>>likely, what am I misunderstanding?
>>
>>Thanks.
>>
>>Bert
>>
>>
>>Bert Gunter
>>
>>"Data is not information. Information is not knowledge. And knowledge
>>is certainly not wisdom."
>> -- Clifford Stoll
>>
>>______________________________________________
>>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>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