R从字符串中删除非字母数字符号

问题描述:

我有一个字符串,我想删除所有非字母数字符号,然后放入一个矢量。所以这个:

I have a string and I want to remove all non-alphanumeric symbols from and then put into a vector. So this:

"This is a string.  In addition, this is a string!" 

会变成:

would become:

>stringVector1

"This","is","a","string","In","addition","this","is","a","string"

我看过 grep()但找不到匹配的示例。任何建议?

I've looked at grep() but can't find an example that matches. Any suggestions?

这里是一个例子:

here is an example:

> str <- "This is a string. In addition, this is a string!"
> str
[1] "This is a string. In addition, this is a string!"
> strsplit(gsub("[^[:alnum:] ]", "", str), " +")[[1]]
 [1] "This"     "is"       "a"        "string"   "In"       "addition" "this"     "is"       "a"       
[10] "string"