Regular expressions are used for pattern matching against strings. They can be used multiple ways, the most common being to check if a string contains some pattern, or to extract some text which matches a pattern. In this instance we're doing the latter.
The first line checks to see if the string $output matches against the regular expression 'Netmask:\s*(.*)\b'. If it matches it goes into the if statement. Breaking out the regex used, there's a couple of things going on...
# look for the text "Netmask:" (no quotes, but colon required)
# followed by any number of white space characters, e.g. tab or space
# the \s is short for whitespace, the * is short for 0 or more
# capture any text after the last white space character
# the parenthesis denotes "capture text", the period is short for any character,
# and the * is short for any number of occurrences
# stop capturing at the end of the word. \b is short for "word boundary"
Assuming it matches the regex, the extracted text will be found in a created array variable, $matches, with the first value ($matches) being equal to the whole of the matched text, and the second and later values ($matches, etc.) equal to the extracted values.
There is a huge amount of information on regex out there. There's a decent reference of the special quantifiers and identifiers here. Regex can be complicated, but they've been around for a long time (Perl uses them heavily), so for most things you can search the internet and find an example or two to base yours off of.
Hope that helps.
If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.