小编Yan*_*roy的帖子

仅用于字符串中的数字的正则表达式?

我找不到只包含空格或整数的字符串的正则表达式。该字符串是用户在键盘上的输入。它可以包含所有内容,但\n(但我猜这无关紧要),但我们可以专注于 ASCII,因为它应该是英语句子 这里有一些例子:

好的:

'1'
'2 3'
'   3 56 '
'8888888       333'
' 039'
Run Code Online (Sandbox Code Playgroud)

不好:

'a'
'4 e'
'874 1231 88 qqqq 99'
' shf ie sh f 8'
Run Code Online (Sandbox Code Playgroud)

我有这个可以找到数字:

t = [int(i) for i in re.findall(r'\b\d+\b', text)]
Run Code Online (Sandbox Code Playgroud)

但我无法获得正则表达式。我的正则表达式目前是,re.match(r'(\b\d+\b)+', text)但它不起作用。

python regex whitespace integer match

5
推荐指数
2
解决办法
5万
查看次数

标签 统计

integer ×1

match ×1

python ×1

regex ×1

whitespace ×1