#------------------------------------------------------------------------------ # remove non-word char == only retian alphanumeric character (char+number) and underscore # eg: # from againinput4@yeah to againinput4yeah # from green-waste to greenwaste def removeNonWordChar(inputString) : return re.sub(r"[^\w]", "", inputString); # non [a-zA-Z0-9_]
例 2.10. removeNonWordChar的使用范例
wxrValidUsername = removeNonWordChar(gVal['blogUser']); wxrValidUsername = wxrValidUsername.replace("_", ""); logging.info("Generated WXR safe username is %s", wxrValidUsername);