import re
s = 'a12a34a56a78 ‘
reg1 = r'a(\d+)a(\d+)a(\d+)a(\d+)'
reg2 = r'(?:a(\d+)){4}' #我的错误示范
1
shoaly 2017-08-07 20:54:52 +08:00
真要是这种有规律的东西 , 用循环加字符串切割吧
|
2
sxm 2017-08-07 21:38:25 +08:00 via Android
(a(\d+))+
|
3
L2AKnG8GXx60bc6P 2017-08-07 21:41:19 +08:00 via iPhone
you need regex
|
4
L2AKnG8GXx60bc6P 2017-08-07 21:44:58 +08:00 via iPhone
i mean
import regex as re |
5
momocraft 2017-08-07 21:50:12 +08:00
ruby 中這個操作叫 scan. 你可以看看 py 有沒有類似的
|
8
inflationaaron 2017-08-08 06:13:15 +08:00
没办法,与其用 regex 不如` split('a')`
|
9
code42 2017-08-20 15:53:08 +08:00
re.findall(r'a(\d+)', 'a12a34a56a78')
|