Rails -v 3.2.3
I’m working with an app that is supposed to display a description & url of a submitted link, I am using regex operators, which is something i am very new too. here is my views code:
(<%= if link.url =~ /(:\/\/) ([^\/]*)/ then $2 else "wrong URL" end %>)
however with every link i submit, the url is always wrong URL….
is this because $2 is the wrong regex operator? or is the /(:\/\/) ([^\/]*)/ section incorrect in Rails 3?
Kill that space in the middle! The regex you’re showing expects a space between the
://and thesub.domain.tldchunks; since no URLs have that, the regex won’t match anything. The simplest change should be:Or, to clean it up a little more (you don’t need the first pair of parentheses):
Hope that helps!