正则表达式中的?表示匹配前面的正则表达式0次或者1次

"""
匹配所有能够表示Python整数的字符串集
"""
patt = '[-+]?\d+'     # "?"代表前面的正则表达式匹配0次或者1次
m = re.match(patt,'98654')
if m is not None:
    print(m.group())

猜你喜欢

转载自blog.csdn.net/beta_safe/article/details/80197849
今日推荐