r - 如何删除R中括号内的标点符号
问题描述
我曾尝试将文档拆分为句子,但由于括号内的标点符号,会出现一些奇怪的结果。所以我想删除任何标点符号。
示例输入:
A <- c('How to remove all punctuations(like this?) in side it?')
想要的输出:
"How to remove all punctuations(like this) in side it?"
解决方案
也许像这样使用积极的前瞻?
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)
推荐阅读
- java - 是否有任何完全免费且可用于商业用途的 OpenJDK
- amazon-web-services - 使用 s3cmd 使 index.html 无效
- mercurial - Mercurial 查找自修订后未修改的文件
- mongodb - 使用 Reactive Mongo 和 Web 客户端的非阻塞功能方法
- angular - Angular 材质 CSS 不适用于移动设备中的 Click 事件
- r - 为什么 spearman 在 zscore 上产生不同的结果?
- php - 在不使用服务器 IP 的情况下使用 docker-compose 时如何在 PHP 中发送 curl 请求
- javascript - 是否可以从类的静态方法调用实例方法?
- firebase - 如何在 Firebase Firestore 中限制集合中的文档
- c++ - 有没有办法在 C++ 中处理一串位