Removing unsafe characters with Python and regex
While working on a program which uses data from an internal CMDB to build ssh
aliases, I ran into a problem. Some of the devices have special characters in the hostname, for example:
DEBUG pre-fix: wcm-449-wu-fw-0/stby
DEBUG pre-fix: wcm-449-wu-fw-0/act
To remove the unsafe characters, the hostname
variable is passed to a cleaning
function each time it is set:
|
|
The unsafe characters are converted to -
:
DEBUG post-fix: wcm-449-wu-fw-0-stby
DEBUG post-fix: wcm-449-wu-fw-0-act