The vi and sed editors use regular expressions as search strings within Substitute commands. You can use the ampersand (&) and quoted digits (\n) special characters to represent the matched strings within the corresponding replacement string.
Within a replacement string, an ampersand (&) takes on the value of the string that the search string (regular expression) matched. For example, the following vi Substitute command surrounds a string of one or more digits with NN. The ampersand in the replacement string matches whatever string of digits the regular expression (search string) matched:
Two character class definitions are required because the regular expression [0–9]* matches zero or ...