\\> is the word boundary that matches the word character (left) and the non-head character (on the right side) or the end of the string $ .
> strings <- c("ten>eight", "ten_>_eight") > gsub("\\>", "greater_", strings) [1] "tengreater_>eightgreater_" "ten_greater_>_eightgreater_"
In the above example, it matches only the word boundary between the word character after n and the character without the word > , as well as the border between t and the end of the line anchor in the first element. And it matches between _ (also the word character) and > , then between t and the end of the line binding (i.e. $ ) in the second element. Finally, it replaces the agreed boundaries with the string you specify.
A simple example:
> gsub("\\>", "*", "f:r(:") [1] "f*:r*(:"
Consider the input line below. ( w means word character, n means non-word character)
f:r(: w___||||| |w|N N | | N
So \\> matches between
Example 2:
> gsub("\\>", "*", "f") [1] "f*"
Input line:
f$ ||----End of the line anchor w
Replacing the agreed boundary with * will give the above result.
Avinash raj
source share