python3正则表达式练习题1-7 匹配所有表示Python整数的字符串集

python版本为3.6.6

源码

>>> patt = '-?\d+'

>>> m = re.match(patt, '--12415415')

>>> if m is not None:m.group()

>>> m = re.match(patt, '-12415415')
>>> if m is not None:m.group()

'-12415415'

>>> m = re.match(patt, '12415415')
>>> if m is not None:m.group()

'12415415'

成功!,正则意思为:’-‘出现零或者一次,后面接出现一次以上的整数~。

猜你喜欢

转载自blog.csdn.net/qq_38115310/article/details/83352154