How to extract a single word from text in R




while mining twitter data I am using:

tweets.df$hashtags <- grep("\\b#MachineLearning\\b",tweets.df$text, value=T)

to extract the text part containing only the #MachineLearning part of the text but it is not coming out properly.
What I actually want is if there is a text: New machines in town #machinelearning #colorado
only machine learning should be the output.
How can I achieve this in R??


one solution could be
ifelse((found<-regexpr("\s#machinelearning", text, perl =TRUE)) !=-1, substring(text, found, found+attr(found,“match.length”)), “nothing”)