Filter through text and return the strings that start with #?
I currently have a te开发者_如何学Goxt form for users to post updates (similar to Twitter), how can I filter through the text thats submitted and return the full strings that start with # (e.g. if a user posts "Hello World! #noob #ruby", I would get #noob and #ruby back) I will likely save the results in a tag db column. Thank you very much for your help!
You can extract pattern-matching substrings out of a larger string using String#scan
# for example, to grab all characters after \# until the next whitespace
"Hello World! #noob #ruby".scan(/\#\S+/) # => ["#noob", "#ruby"]
精彩评论