use () around the part of the match you want to extract, i.e.
if part =~ /\[(\d*)\]/
puts $1 # $2 would mean the second group of (), and so on
btw, you really should get that code out of your view, and put it
into a helper or model...