regular expressions in Ruby on rails

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 else ... end

btw, you really should get that code out of your view, and put it into a helper or model...