How can you return everything after last slash(/) in a Ruby string [closed]

I don’t think a regex is a good idea, seeing how simple the task is:

irb(main):001:0> s="https://www.facebook.com/hackerbob"
=> "https://www.facebook.com/hackerbob"
irb(main):002:0> s.split("https://stackoverflow.com/")[-1]
=> "hackerbob"

Of course you could also do it using regex, but it’s a lot less readable:

irb(main):003:0> s[/([^\/]+)$/]
=> "hackerbob"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)