python中的正则表达式,检查字符串是否只包含字母、数字和点(.)

Joa*_*iay 5 python regex python-2.7

如果一个字符串只包含字母、数字、空格和点(.)并且没有顺序,我正在尝试开发一个用于匹配的正则表达式。

像这样:

hello223 3423.  ---> True
lalala.32 --->True
.hellohow1 ---> True
0you and me = ---> False (it contains =)
@newye ---> False (it contains @)
With, the name of the s0ng .---> False (it start with ,)
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用这个,但总是返回匹配:

m = re.match(r'[a-zA-Z0-9,. ]+', word)
Run Code Online (Sandbox Code Playgroud)

任何的想法?

表述这个问题的另一种方式是,是否有任何不同的字母、数字、点和空格字符?

提前致谢

lll*_*lll 5

您需要添加$

re.match(r'[a-zA-Z0-9,. ]+$', word)
Run Code Online (Sandbox Code Playgroud)