The regsubst function takes at least three parameters: source, pattern, and replacement. In our example, we specified the source string as $::ipaddress, which, on this machine, is as follows:
10.0.2.15
We specify the pattern function as follows:
(.*)\..*
We specify the replacement function as follows:
\1.0
The pattern captures all of the string up to the last period (\.) in the \1 variable. We then match on .*, which matches everything to the end of the string, so when we replace the string at the end with \1.0, we end up with only the network portion of the IP address, which evaluates to the following:
10.0.2.0
We could have got the same result in other ways, of course, including the following:
$class_c = regsubst($::ipaddress, '\.\d+$', '.0')
Here, we only match the last octet and replace it with .0, which achieves the same result without capturing.