I am looking to find forward slash tags in posts to my website. How can I use scan in Rails to do this? This should get the / then the words following. For instance it would be "This is my message /slash" and I am looking to scan for /slash.
@forward_slashes ||= message.scan( )
I’m not entirely clear on your question, as it’s in broken English. I think you’re just referring to the ruby String method method scan – nothing rails-specific about it.
It just takes a regular expression. /(\/.*)/ will match from the first forward slash to the end of the string.
my_string.scan(/\/.*/) {|slash_stuff| puts slash_stuff}
edit: using \w+ will only return the first word after the slash. .* will return everything until the end of the string.
edit: using split will break it up into >2 pieces if there are multiple forward slashes, which isn’t clear from your description what you would want for an input of hi / there / person – do you want “/ there / person” (use scan) or ” there ” and ” person” (use split)