小伙看你根骨奇佳,潜力无限,来学PHP伐。
You can use the re.sub function to perform regular replacement, sub(pattern, repl, string, count=0)
First parameter: Rule
The second parameter: the replaced string
The third parameter: string
The fourth parameter: the number of replacements. Defaults to 0, meaning every match is replaced
>>> a="\t\t\n 123" >>> a '\t\t\n 123' >>> b = re.sub(r'\s+','', a) #\s 匹配任意的空白符 >>> b '123'
You can use the re.sub function to perform regular replacement,
sub(pattern, repl, string, count=0)
First parameter: Rule
The second parameter: the replaced string
The third parameter: string
The fourth parameter: the number of replacements. Defaults to 0, meaning every match is replaced