Python's string count function doesn't use regex
<p>when trying to count all letters in a string using the count function and the regex [A-Za-z], it returns a a value of zero.</p>

<p>For instance:</p>

<pre><code>string="Hi, everybody. Let's dance!"

string.count('[A-Za-z]') ## prints 0
</code></pre>

<p>any suggestions?</p>

<p>As indicated in brianpcks comment, there are alternatives that do not require using regular expressions:</p>

<pre><code>len(c for c in string if c.isalpha())
</code></pre>

<p>or</p>

<pre><code>from string import ascii_lowercase
len(c for c in string if c in string.ascii_lowercase)
</code></pre>

<p>Although these alternatives might be slower in CPython, your mileage may vary using other Python implementations (especially PyPy, who's JIT can optimize python loops very well).</p>

<p>As always, if speed is a concern, benchmark both approaches in your environment before deciding which to use.</p>

python regex python-2.7 function