Python正则匹配空格

我需要只匹配到空格,不要匹配到换行符/n/t之类的,也就是不能直接用/s

import re

text = "Hello World\nThis is a test string with spaces."
pattern = r' '

matches = re.findall(pattern, text)
print(matches)

可以使用[ ],pattern = r"[ ]{3}",这里的[ ]是一个字符集,表示仅匹配一个空格字符。{3}表示匹配连续出现的三次。