爲什麼轉義角度支架>
的轉義表現出前瞻性的行爲?轉角支架的作用類似於前視
要清楚,我知道角架不需要被轉義。
是,如何被解釋模式的問題,它產生出的匹配(ES)
## 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)
一些跟進的問題:
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?
'\\>'=字邊界.. – 2014-10-07 14:14:54