Equivalent angle bracket acts similarly to perspective

Why does the acceleration coming out of the angle bracket > show a look like behavior?

To be clear, I understand that an angle bracket does not require flight.
The question is how is the template interpreted that gives the result (s) shown

 ## match bracket, with or without underscore ## replace with "greater_" strings <- c("ten>eight", "ten_>_eight") repl <- "greater_" ## Unescaped. Yields desired results gsub(">_?", repl, strings) # [1] "tengreater_eight" "ten_greater_eight" ## All four of these yield the same result gsub("\\>_?", repl, strings) # (a) gsub("\\>(_?)", repl, strings) # (b) gsub("\\>(_)?", repl, strings) # (c) gsub("\\>?", repl, strings) # (d) gsub("\\>", repl, strings) # (e) # [1] "tengreater_>eightgreater_" "ten_greater_>_eightgreater_" gregexpr("\\>?", strings) 

Some further questions:

 1. Why do `(a)` and `(d)` yield the same result? 2. Why is the end-of-string matched? 3. Why do none of `a, b, or c` match the underscore? 
+3
regex r gsub
source share
1 answer

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

  • f and :
  • r and (

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.

+3
source share

All Articles