将标点符号转换为空格

scr*_*Owl 3 regex string r

我有一堆带有标点符号的字符串,我想将其转换为空格:

"This is a string. In addition, this is a string (with one more)."
Run Code Online (Sandbox Code Playgroud)

会成为:

"This is a string  In addition  this is a string  with one more  "
Run Code Online (Sandbox Code Playgroud)

我可以通过stringrpackage(str_replace_all())一次手动执行此操作(,/./!/(/)/等),但我很好奇是否有更快的方式我假设使用正则表达式.

有什么建议?

mds*_*ner 10

x <- "This is a string. In addition, this is a string (with one more)."
gsub("[[:punct:]]", " ", x)
[1] "This is a string  In addition  this is a string  with one more  "
Run Code Online (Sandbox Code Playgroud)

看看?gsub这样的快速替换,以及 ?regex关于[[:punct:]]类的详细信息,即

‘[:punct:]’ Punctuation characters:
      ‘! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { |
      } ~’.
Run Code Online (Sandbox Code Playgroud)