代码:
1 import re
2
3 str1 = 'asdf12dvdve4gb4'
4 pattern1 = re.compile('\d+')
5 pattern2 = re.compile('[0-9]')
6 mch1 = pattern1.findall(str1)
7 mch2 = pattern2.findall(str1)
8 print('mch1:\t%s'% mch1)
9 print('mch2:\t%s'% mch2)
10
11 #输出结果
12 mch1: ['12', '4', '4']
13 mch2: ['1', '2', '4', '4']
问题:
第8、9行的“t”, “%s” ,“%”表示什么意思?
你问题中的不是正则表达式
\t 是转义字符
%s 是字符串格式化符号(格式化占位)
转义字符
字符串格式化符号
更多
Python 字符串