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>You can use the <code>{3}</code> to ask for 3 consecutive digits only and prepend underscore:</p>

<pre><code>eg_list = ['test_model_01', 'test_romeo_005', 'test_charlie_rig']
for item in eg_list:
    match = re.search(r'_([0-9]{3})$', item)
    if match:
        print(match.group(1))
</code></pre>

<p>This would print <code>005</code> only.</p>

python maya