Fix Python – How can I check if a string contains ANY letters from the alphabet?

Question

Asked By – papezjustin

What is best pure Python implementation to check if a string contains ANY letters from the alphabet?

string_1 = "(555).555-5555"
string_2 = "(555) 555 - 5555 ext. 5555

Where string_1 would return False for having no letters of the alphabet in it and string_2 would return True for having letter.

Now we will see solution for issue: How can I check if a string contains ANY letters from the alphabet?


Answer

Regex should be a fast approach:

re.search('[a-zA-Z]', the_string)

This question is answered By – JBernardo

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0