Natasha
Natasha

Reputation: 13

regexp to find hashtags

This is for Matlab. I have a tweet and I need to find what the hashtags say. I know I can isolate and save to a variable everything that starts with a '#' and ends with a ' ' using regexp. But, when I use

    tweet = 'it is fun to post on #stackoverflow, really #itis';
    regexp(tweet,'#(\w+)','tokens','once')
    ans = 
        'stackoverflow'

I only get the first #. How would I make it so that I could get the "itis" # as well?

Upvotes: 1

Views: 371

Answers (3)

e0571302
e0571302

Reputation: 116

I think this is what you're looking for:

regexp(tweet,'#(\w+)','match')
ans = 
'#stackoverflow'    '#itis'

However, it seems as if you know more about Regex than I do, so I guess you know how to get rid of the #'s in the string.

Upvotes: 0

dchellaram
dchellaram

Reputation: 56

According to the matlab documentation, you need to remove the 'once'. Source: http://www.mathworks.com/help/matlab/ref/regexp.html

Upvotes: 0

Wrikken
Wrikken

Reputation: 70470

once returns only the first match.... Drop that if you don't want that.

Upvotes: 4

Related Questions