how to enumerate string placeholders?
<p>I'd like to know what's the best way to enumerate placeholders from strings, I've seen there is already another post which asks <a href="https://stackoverflow.com/questions/14061724/how-can-i-find-all-placeholders-for-str-format-in-a-python-string-using-a-regex">how-can-i-find-all-placeholders-for-str-format-in-a-python-string-using-a-regex</a> but I'm not sure the answers provided are giving me exactly what I'm looking for, let's examine this little test:</p>

<pre><code>import string

tests = [
    ['this is my placeholder 1 {} and this is the 2 {}', 2],
    ['another placeholder here {} and here \"{}\"', 2]
]
for s in tests:
    num_placeholders = len([
        name for text, name, spec, conv in string.Formatter().parse(s[0])])
    if num_placeholders != s[1]:
        print("FAIL: {0} has {1} placeholders!!! excepted result {2}".format(
            s[0], num_placeholders, s[1]))
</code></pre>

<p>It seems <a href="https://docs.python.org/2/library/string.html#string.Formatter" rel="nofollow noreferrer">string.Formatter</a> is not giving me the expected answer I'm looking for:</p>

<pre><code>FAIL: another placeholder here {} and here "{}" has 3 placeholders!!! excepted result 2
</code></pre>