$1 is a global variable which is set to the value matched by the bracketed bits. You just treat it like any string. e.g. "The first parameter was #$1" or number = $2.to_f In gsub substitutions the letters '\N' in the substitution text, where N is a number from 1 to 9, will be replaced by the substituted sequence. If you use double quotes, you will need two backslashes because this is not a normal escape sequence. str = "We love Ruby" puts str.gsub(/We (\w+) \w+/, 'Why do we \1 it?') puts str.gsub(/(\w+)$/, "it because \\1 allows us to do cool stuff!")