如何删除R中括号内的标点符号
How to remove punctuation inside brackets in 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)
我曾尝试将文档拆分成句子,但由于括号内的标点符号,结果有些奇怪。所以我想删除所有标点符号。
示例输入:
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)