从字符串[重复项]中删除初始(匹配)模式>> [

问题描述 投票:0回答:2

v<-c("RT @name1: hello world", "Hi guys, how are you?", "Hello RT I have no text", "RT @name2: Hello!")

我只想删除位于字符串开头的RT并将结果存储在另一个向量中,例如w

> w "@name1: hello world" "Hi guys, how are you?" "Hello RT I have no text" "@name2: Hello!"

也许我可以使用软件包str_extract_all中的函数stringr,但无法将其应用于我的问题。

我具有以下字符串向量:v

r regex
2个回答
1
投票
使用gsub和'anchor'^,它表示字符串的开头:

0
投票
<- str_replace(v,"^RT","")
© www.soinside.com 2019 - 2024. All rights reserved.