# Extracting hash tags from string

**URL:** <https://www.ruby-forum.com/t/extracting-hash-tags-from-string/157578>\
**Category:** Rails\
**Created:** [January 13, 2009, 10:29am UTC](https://www.ruby-forum.com/t/extracting-hash-tags-from-string/157578 "2009-01-13T10:29:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcarlson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mcarlson](https://www.ruby-forum.com/u/mcarlson)\
**Post date:** [January 13, 2009, 10:29am UTC](https://www.ruby-forum.com/t/extracting-hash-tags-from-string/157578/1 "2009-01-13T10:29:03Z")

</div>

Hello,

I am playing around with the Twitter API and I am trying to extract  
the hash tags from the updates. Something like this:

“This is the string that I want to pull #tags #out #of”

I have the regex that gets the tags, but I am not sure how to extract  
them from the string into an array.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mcarlson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mcarlson](https://www.ruby-forum.com/u/mcarlson)\
**Post date:** [January 13, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/extracting-hash-tags-from-string/157578/2 "2009-01-13T15:49:09Z")

</div>

Pass the regex to String#scan, which will return an array of matches.  
Check  
the docs for details.

Regards,  
Craig
