如何应用gsub替换不在范围内的字符

时间:2012-03-01 18:10:01

标签: regex r

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以外的所有字符 认为这将是正确放置括号的问题,但似乎无法解决问题

欢呼声

1 个答案:

答案 0 :(得分:4)

> gsub("[^a-c]", ".", letters[1:10])
 [1] "a" "b" "c" "." "." "." "." "." "." "."

详情请见此处:http://www.regular-expressions.info/posixbrackets.html