且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

逃脱成角度的支架的行为类似于前瞻

更新时间:2022-06-14 23:16:20

\\>是单词边界(在左侧的单词字符和右侧的非单词字符或末尾匹配)线锚$的位置.

\\> 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_"

在上面的示例中,它仅匹配n之后的单词字符和非单词字符>之间的单词边界,然后匹配t与第一个元素中的行锚末端之间的边界.并且它在_(也是单词字符)和>之间匹配,然后在t和第二个元素中的行锚结尾(即$)之间匹配.最后,它将匹配的边界替换为您指定的字符串.

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.

一个简单的示例:

> gsub("\\>", "*", "f:r(:")
[1] "f*:r*(:"

请考虑以下输入字符串. ( w表示单词字符,N表示非单词字符)

Consider the below input string. (w means a word character, N means a non-word character)

    f:r(:
w___|||||
     |w|N
     N |
       |
       N

所以\\>之间匹配,

  • f:
  • r(
  • f and :
  • r and (

示例2:

> gsub("\\>", "*", "f") 
[1] "f*"

输入字符串:

f$
||----End of the line anchor
w

*替换匹配的边界将得到以上结果.

Replacing the matched boundary with * will give the above result.