I’m working in a Rails controller. I call a wget command system(wget ...), and I want a variable that indicates the filename of the downloaded file.
For instance, for wget google.com, or wget www.google.com, or wget www.google.com/, or wget http://www.google.com, the returned name should be index.html.
For example.com/firstpage.html, the return name should be firstpage.html.
As you can see, I can’t simply just strip the name after the last backslash. How can I do it?
Regex can do it!
Process the string you get with regex to find everyting after the last /
This regex also handles multiple forwards slashes so it can work with long urls too.
codepad example and a good place to test your ruby regex