For completeness, should the attempt check be "<=" rather than "<" in the case that someone would ever pass in 1 for @netwait_max_attempts?

Minor comment as well in that the check for the count of attempts could occur first in the if statement rather than the regular expression match