实例
去除所有的空白符
# encoding: utf-8
import re
sentence = "hello apple \n \r \t"
pattern = re.compile(r"\s+")
sentence = re.sub(pattern, '', sentence)
print(sentence)
#output: helloapple
# encoding: utf-8
import re
sentence = "hello apple \n \r \t"
pattern = re.compile(r"\s+")
sentence = re.sub(pattern, '', sentence)
print(sentence)
#output: helloapple
本文标题:Python 正则表达式
本文链接:https://www.haomeiwen.com/subject/dvudnhtx.html
网友评论