regEx - Isolate punctuation in Python 3.x
Question: I have been trying to use the regEx module (regular expression) to single out
punctuation, but I just can't figure it out. Does anyone have any useful
information on this?

    
    
    import re
    
    n = True
    while n == True:
        name = input("What is your name?\n")
        invalid = re.findall(r'[^\s\w]', name)
        if invalid:
            print("Invalid!")
        else:
            print("That is a valid name.")
            n = False
    
    name = name.lower()
    name = name.title()
    

This is the new, updated code. Still looking for ways to break it. Comment if
you find some way that it'll accept punctuation.


Answer: When you something like this `re.match("[A-Z]",name)` you match that there is
a capital letter (at least one) contained in `name`. Try that instead:

    
    
    import re
    import string
    n = True
    while n == True:
        name = input("What is your name?\n")
        chars = set(string.punctuation+'1234567890')
        if any((c in chars) for c in name):
            print("Invalid!")
        else:
            print("That is a valid name!")
            n=False
    

