I am trying to develop a regular expression for match if a string just contains letters, numbers, space and dot(.) anywhere and with no order.
Like this:
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 ,)
I am trying with this one but is always returning match:
m = re.match(r'[a-zA-Z0-9,. ]+', word)
Any idea?
Other way to formulate the question is are there any character diferent of letters, numbers, dot and space?
Thanks in advance
You need to add $:
re.match(r'[a-zA-Z0-9,. ]+$', word)
                        re.search() solution:
import re
def contains(s):
    return not re.search(r'[^a-zA-Z0-9. ]', s)
print(contains('hello223 3423.'))    # True
print(contains('0you and me = '))    # False
print(contains('.hellohow1'))        # True
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With