Skip to content Skip to sidebar Skip to footer

Check If String Contains Only Alphabets In Python

I have strings in this form: string space string space string , test , test test1 test2 [ test test1 What I want is for all the three strings to only have alphabets, and if it doe

Solution 1:

Your regex will only work if there are two spaces in the string and will return true even if the beginning of the string contains invalid characters.

If your desired characters are alphabet, numbers and whitespace try

^[a-zA-Z0-9\s]*$

If you only want alphabet characters and whitespace try

^[a-zA-Z\s]*$

If you don't want to match an empty string then replace the * with a +

Post a Comment for "Check If String Contains Only Alphabets In Python"