[英]gsub: Removing a special character at the end of a string in R
我想在R中替换字符串末尾的所有* s。
txt <- c("arm","foot-ha-*","lefroo", "bafoobar*")
gsub("/\\*$/","",txt, perl=TRUE);
我想将txt转换为“ arm”,“ foo-ha-”,“ lefroo”,“ bafoobar”
我究竟做错了什么?
谢谢!
您在正则表达式中不需要/
。
gsub("\\\\*$", "", txt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.