regex for only numbers in string?

后端 未结 3 1533
野性不改
野性不改 2021-01-19 09:10

I can\'t find the regex for strings containing only whitespaces or integers. The string is an input from user on keyboard. It can contain everything but \\n (bu

3条回答
  •  有刺的猬
    2021-01-19 09:18

    >>> re.match(r'^([\s\d]+)$', text)
    

    You need to put start (^) and end of line ($) characters in. Otherwise, the part of the string with the characters in will match, resulting in false positive matches

提交回复
热议问题