Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove all words that start with "@" from a string

Tags:

r

how can I remove all words that start with "@" from a string?

For example, "@AgnezMo On @AirAsia Airbus A320-216 Fleet with @NinetologyMY Livery -- 9M-AHG cc: @AgnesMonicaEnt @agnezone http://t.co/hfXwUQq2Oq"

I would like to have the string to be "On Airbus A320-216 Fleet with Livery -- 9M-AHG cc: http://t.co/hfXwUQq2Oq"

like image 831
user3456230 Avatar asked Mar 24 '14 16:03

user3456230


2 Answers

Try this where s is the input:

gsub("@\\w+ *", "", s)

giving:

"On Airbus A320-216 Fleet with Livery -- 9M-AHG cc: http://t.co/hfXwUQq2Oq"
like image 113
G. Grothendieck Avatar answered Oct 15 '22 17:10

G. Grothendieck


Hi you can do like this :

xx <-  "@AgnezMo On @AirAsia Airbus A320-216 Fleet with @NinetologyMY Livery -- 9M-AHG cc: @AgnesMonicaEnt @agnezone http://t.co/hfXwUQq2Oq"
gsub("@([a-zA-Z0-9]|[_])*", "", xx)

## [1] " On  Airbus A320-216 Fleet with  Livery -- 9M-AHG cc:   http://t.co/hfXwUQq2Oq"
like image 35
Victorp Avatar answered Oct 15 '22 16:10

Victorp