为什么带有边界的\ S +不能提取非空格字符?

时间:2018-07-17 15:28:03

标签: python regex

print(re.search(r'\b\w+\b', '\t hell0_there(0,1) \tbbb'))     # Works fine - 'hell0_there'
print(re.search(r'\S+', '  hell0_there(0,1)\t bbb'))          # Works fine - 'hell0_there(0,1)'

print(re.search(r'\b\S+\b', '  hell0_there(0,1)  '))      # Missing paranthesis - 'hell0_there(0,1'
print(re.search(r'\b\S+\b','   1.3.6.1.4.1.9848.3.2.2.3(1,0)   ')) # Missing closed paranthesis

print(re.search(r'\b\S+\b', '\t hell0_there(0,1) \tbbb'))      # Same issue
print(re.search(r'\b\S+\b','\t  1.3.6.1.4.1.9148.3.2.2.3(1,0)  \tnnn')) # Same issue

为什么非空间边界('\b\S+\b')不能用封闭的括号提取?

0 个答案:

没有答案