简体   繁体   English

如何删除R中的所有英语单词(特殊标点除外)

[英]how to delete all English words, except special punctuation, in R

I have a data file in R, 我在R中有一个数据文件,

data <- "conflict need resolved :<  turned conversation exchange ideas richer environment one tricky concepts :D    conflict  always top business agendas :>  maybe different ideas opinions different :)" 

from this I want to remove all words, only the smiles will be there, and the output I am expecting, 我想从中删除所有单词,只有微笑会在那里,以及我期望的输出,

":< :D :> :)"

Is there any library or method in R for doing this task easily? R中是否有任何库或方法可以轻松完成此任务?

You can use [[:alnum:]] as a regexp pattern for all numeric and alphanumeric characters of a string 您可以将[[:alnum:]]用作字符串的所有数字和字母数字字符的正则表达式模式

s <- gsub("[[:alnum:]]*", "", "conflict need resolved :<  turned conversation exchange ideas richer environment one tricky concepts :D    conflict  always top business agendas :>  maybe different ideas opinions different :) ")
gsub(" +", " ", s)

[1] " :< : :> :) "

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 删除 R 中除反斜杠以外的所有标点符号 - Remove all punctuation except backslash in R 在R中使用正则表达式删除字符串中除指定单词以外的所有字符 - Use regex in R to delete all characters in a string except specified words 删除字符串中所有包含标点(R)的单词 - Remove all words in string containing punctuation (R) Python 3 正则表达式:删除所有标点符号,特殊单词模式除外 - Python 3 Regex: remove all punctuation, except special word pattern 是否可以将所有特殊字符和标点符号(除句点)分割成字符串? - Is it possible to split a string by all special characters and punctuation EXCEPT period? RegEx是否可以匹配除标点符号之外的所有非单词? - RegEx for matching all non-words except punctuation? 正则表达式按空格和所有标点符号分隔单词 - Regex split words by spaces and all punctuation marks except 非英语字符,标点符号等特殊字符或单词开头或中间的数字的单词数 - Number of words with non-English characters, special characters such as punctuation, or digits at beginning or middle of word 如何匹配所有语言字符(如英语,希腊语,中文)(特殊字符除外) - how to match all language characters like english, greek, chinese except the special characters 正则表达式 function 删除除指定表达式之外的所有数字和标点符号? - Regex function to delete all numbers and punctuation except a specified expression?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM