我正在使用 R 并且有一个大型推文数据框。我想要一个 grep 调用来选择仅由主题标签组成的推文(希望从最终数据帧中排除这些内容)。
我最初的 grep 工作:
hashtagonly_tweets_INDEX = grep("^#\\w*[^\\w]", allTweets$V1,
value=F,
ignore.case = T,
fixed=F)
我希望这会选择以主题标签 ^#\w* 开头的多个单词,而不是选择没有主题标签 [^\w] 的单词。
但是,我现在显然已经没有人才了,因为收集的推文类型仍然包含主题标签中的文本,例如:
#wtf is even happening right now. this truck is driving 50 down the center of the highway. #learntodrive
#WhatGrindsMyGears When someone pulls out in front of me then never proceeds to go the speed limit or above. #roadrage
#Traffic in #Westminster #travel #roadrage #transport #London #tourism #sightseeing #dark #clouds
非常感谢任何建议,
谢谢
最佳答案
不确定我是否很好地理解你的问题,这是一个匹配仅包含主题标签的推文的正则表达式:
^\s*(?:#\w+\s*)+$
关于regex - 仅包含主题标签的推文的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28007309/