There are two ever-so-slightly different engines of regular expressions implemented in R. The default is called POSIX-consistent; all regex functions in R are also equipped with an option to turn on the latter type: perl = TRUE
.
perl = TRUE
enables look-ahead and look-behind in regular expressions.
"(?<=A)B"
matches an appearance of the letter B
only if it's preceded by A
, i.e. "ABACADABRA"
would be matched, but "abacadabra"
and "aBacadabra"
would not.