gpt4 book ai didi

regex - R正则表达式删除除撇号以外的所有标点符号

转载 作者:行者123 更新时间:2023-12-04 09:41:07 28 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Remove all punctuation except apostrophes in R

(4 个回答)


8年前关闭。




我正在尝试从字符串中删除除撇号以外的所有标点符号。这是我的 exastr2 <-

str2 <- "this doesn't not have an apostrophe,.!@#$%^&*()"
gsub("[[:punct:,^\\']]"," ", str2 )
# [1] "this doesn't not have an apostrophe,.!@#$%^&*()"

我究竟做错了什么?

最佳答案

“否定先行断言”可用于在任何撇号被测试为标点符号之前从考虑中删除它们。

gsub("(?!')[[:punct:]]", "", str2, perl=TRUE)
# [1] "this doesn't not have an apostrophe"

关于regex - R正则表达式删除除撇号以外的所有标点符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15255709/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com