我希望在 R 中替换字符串末尾的所有 *。
txt <- c("arm","foot-ha-*","lefroo", "bafoobar*")
gsub("/\\*$/","",txt, perl=TRUE);
我想将txt转换为 “arm”“foo-ha-”“lefroo”“bafoobar”
我做错了什么?
谢谢!
最佳答案
您不需要正则表达式中的 /
。
gsub("\\*$", "", txt)
关于r - gsub : Removing a special character at the end of a string in R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16994256/