【问题标题】:How to remove punctuation inside brackets in R如何删除R中括号内的标点符号
【发布时间】:2018-11-13 06:18:02
【问题描述】:

我曾尝试将文档拆分为句子,但由于括号内的标点符号,会出现一些奇怪的结果。所以我想删除所有标点符号。

示例输入:

A <- c('How to remove all punctuations(like this?) in side it?')

想要的输出:

"How to remove all punctuations(like this) in side it?"

【问题讨论】:

标签: r brackets punctuation


【解决方案1】:

也许像这样使用积极的前瞻?

gsub("[?!;,.](?=\\))", "", A, perl = T)
#[1] "How to remove all punctuations(like this) in side it?"

或使用 POSIX 字符类

gsub("[[:punct:]](?=\\))", "", A, perl = T)

或者如果您需要匹配其他类型的右括号(例如花括号、方括号)

gsub("[[:punct:]](?=[)\\]}])", "", A, perl = T)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2021-11-21
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多