Regex to extract keyword from tweet -
i'm trying match 'apple' in tweet data twitter. want able match hashtags too, match 'apple' either: 'apple' or '#apple'.
edit: example tweet might be:
"today going eat apple"
or
"today going eat #apple"
i not want match:
"today going eat lots of apples"
i managed match hashtags using following \s#([^ ]*)
, how make hashtag optional?
eventually need create 2 variations, 1 case sensitive , 1 case insensitive.
you can make hash optional appending question mark:
\s#?([^ ]*)
Comments
Post a Comment