This question already has an answer here:
I just learned about \K
in regex, and was wondering if somebody could explain how it's different from a lookbehind.
For example, the following two gsubs are identical, as far as I can tell:
tst<-"This is the day. That is the day"
gsub("This is the \\Kday","week",tst, perl=TRUE)
gsub("(?<=This is the )day","week",tst,perl=TRUE)
Maybe I'm not thinking complex enough, but can anyone give an example where one makes sense but the other doesn't and vice versa?
One thing I could think of is that a lookbehind has to be of a fixed length (right? I get an error when I try to use .*
in a lookbehind), but then why use a lookbehind instead of \K
?