如何使用正则表达式在Python中匹配空白?
以下代码匹配给定字符串中的空白。
阅读更多:Python 教程
示例
import re
result = re.search(r'[\s]', 'The Indian Express')
print result
输出
<_sre.SRE_Match object at 0x0000000005106648>
示例
以下代码查找给定字符串中的所有空白并打印出它们。
import re
result = re.findall(r'[\s]', 'The Indian Express')
print result
输出
[' ', ' ']
极客教程