tags:

views:

72

answers:

3

I need to grab a string like

"/html/body/a"

i need to check the last portion, in this case "a" after the final "/"

how can i do this ? how can i regex match for the last item after the final "/" ?

+6  A: 
x = "/html/body/a"
x.split("/").last  # => "a"
Pesto
+4  A: 

Regex? Not sure, but what's wrong with

my_string.split("/").last # Maybe you want some error checking here, I don't know.
David Seiler
+4  A: 

If you want to use regexp, this would be it:

mystring = "/html/body/a"
if mystring =~ /([^\/]+)$/
    last_part = $1
end
Magnar
+1 for actually answering the question posed :)
David Seiler