我正在使用python试图编写一些简单的代码,通过正则表达式查找字符串并查找内容。在此字符串中:一个非常简单的正则表达式的问题
and the next nothing is 44827
我希望我的正则表达式只返回数字。
我已经建立了我的Python程序是这样的:
buf = "and the next nothing is 44827"
number = re.search("[0-9]*", buf)
print buf
print number.group()
什么number.group()返回的是一个空字符串。然而,当正则表达式是:
number = re.search("[0-9]+", buf)
正确提取完整数字(44827)。我在这里错过了什么?