Check for very specified numbers padding
<p>I am trying to check for a list of items in my scene to see if they bear 3 (version) paddings at the end of their name - eg. <code>test_model_001</code> and if they do, that item will be pass and items that do not pass the condition will be affected by a certain function..</p>

<p>Suppose if my list of items is as follows:</p>

<ul>
<li>test_model_01</li>
<li>test_romeo_005</li>
<li>test_charlie_rig</li>
</ul>

<p>I tried and used the following code:</p>

<pre><code>eg_list = ['test_model_01', 'test_romeo_005', 'test_charlie_rig']
for item in eg_list:
    mo = re.sub('.*?([0-9]*)$',r'\1', item)
    print mo
</code></pre>

<p>And it return me <code>01</code> and <code>005</code> as the output, in which I am hoping it will return me just the <code>005</code> only.. How do I ask it to check if it contains 3 paddings? Also, is it possible to include underscore in the check? Is that the best way?</p>

<p>I usually don't like regex unless needed. This should work and be more readable.</p>

<pre><code>def name_validator(name, padding_count=3):
    number = name.split("_")[-1]
    if number.isdigit() and number == number.zfill(padding_count):
        return True
    return False

name_validator("test_model_01") # Returns False
name_validator("test_romeo_005") # Returns True
name_validator("test_charlie_rig") # Returns False
</code></pre>

python maya