strin-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:18:33 24 4
gpt4 key购买 nike

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

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


会成为:

>stringVector1

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


我看过 grep(),但找不到匹配的示例。有什么建议?

最佳答案

这是一个例子:

> 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"

关于regex - R从字符串中删除非字母数字符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8959243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com