3

the output of

strsplit('abc dcf', split = '(?=c)', perl = T)

is as expected.

However, the output of

strsplit('abc dcf', split = '(?!c)', perl = T)

is

[[1]]
[1] "a" "b" "c" " " "d" "c" "f"

while my expectation is

[[1]]
[1] "a"  "b"  "c " "d"  "cf"

becasue I thought it wouldn't be splited if the last character of previous chunk matches the char c. Is my understanding of negative lookahead wrong?

mt1022
  • 15,959
  • 5
  • 40
  • 65

1 Answers1

1

We can try

strsplit('abc dcf', "(?![c ])\\s*\\b", perl=TRUE)
#[[1]]
#[1] "a"  "b"  "c " "d"  "cf"
akrun
  • 789,025
  • 32
  • 460
  • 575