Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 R 中工作并且在逃避反斜杠时遇到了麻烦。我正在使用图书馆stringr。
stringr
install.packages("stringr", repos='http://cran.us.r-project.org') library("stringr")
我想要做str = str_replace_all(str, "\", "")
str = str_replace_all(str, "\", "")
所以我尝试str = str_replace_all(str, "\\", "")了,但它不会工作。
str = str_replace_all(str, "\\", "")
我该怎么办?
我找到了一个可行的解决方案
str = gsub("([\\])","", str)
使用Hmisc::escapeRegexand Hmisc::escapeBSwhich 会自动转义反斜杠和其他正则表达式特殊字符。
Hmisc::escapeRegex
Hmisc::escapeBS