Ruby gsub / regex modifiers?

regex, ruby

Solution

Zenspider's Quickref contains a section explaining which escape sequences can be used in regexen and one listing the pseudo variables that get set by a regexp match. In the second argument to gsub you simply write the name of the variable with a backslash instead of a $ and it will be replaced with the value of that variable after applying the regexp. If you use a double quoted string, you need to use two backslashes.

When using the block-form of gsub you can simply use the variables directly. If you return a string containing e.g. \1 from the block, that will not be replaced with $1. That only happens when using the two-argument form.

Problem

Where can I find the documentation on the modifiers for `gsub`? \a \b \c \1 \2 \3 %a %b %c $1 $2 %3 etc.? Specifically, I'm looking at this code... `something.gsub(/%u/, unit)` what's the `%u`?

Original source