Quicky
gsub("[a-c]",".", txt) # replaces all a,b,c with a period
gsub("^a",".", txt) # replaces all characters other than a with a period
如何用句点替换a,b,c以外的所有字符 认为这将是正确放置括号的问题,但似乎无法解决问题
欢呼声
答案 0 :(得分:4)
> gsub("[^a-c]", ".", letters[1:10])
[1] "a" "b" "c" "." "." "." "." "." "." "."
详情请见此处:http://www.regular-expressions.info/posixbrackets.html