Ruby で作ってみた

# 最後のドットと、_ の間の文字列を抜き出す。該当なしなら、nil を返す

def slice_string( input_str )
pos_1 = input_str.rindex( "." ) # 文字列の末尾から探す
return nil unless pos_1

pos_2 = input_str.index( "_", pos_1 + 1 ) # ドットの次の文字から探す
return nil unless pos_2

return input_str.slice( pos_1 + 1 ... pos_2 )
end

input_ary = %w(.foo.xxx_var .foo.foo.yyy_var .zz zz)

p input_ary.map{ |str| slice_string( str ) }
#=> [ "xxx", "yyy", nil, nil ]