Why does escaping escaping the angled bracket > exhibit the look-ahead like behavior?
To be clear, I understand that the angled bracket does not nece
\\> is a word boundary Which matches between a word character(in the left side) and a non-word character (in the right side) or end of the line anchor $.
> strings <- c("ten>eight", "ten_>_eight")
> gsub("\\>", "greater_", strings)
[1] "tengreater_>eightgreater_" "ten_greater_>_eightgreater_"
In the above example it match only the word boundary exists between a word character after n and a non-word character > then also the boundary between t and end of the line anchor in the first element. And it matches between _ (also a word character) and > then between t and end of the line anchor (ie, $) in the second element. Finally it replaces the matched boundaries with the string you specified.
A simple example:
> gsub("\\>", "*", "f:r(:")
[1] "f*:r*(:"
Consider the below input string. (w means a word character, N means a non-word character)
f:r(:
w___|||||
|w|N
N |
|
N
So \\> matches between,
f and :r and (Example 2:
> gsub("\\>", "*", "f")
[1] "f*"
Input string:
f$
||----End of the line anchor
w
Replacing the matched boundary with * will give the above result.