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>The asterisk after the [0-9] specification means that you are expecting any random number of occurrences of the digits 0-9.  Technically this expression matches test_charlie_rig as well. You can test that out here <a href="http://pythex.org/" rel="nofollow">http://pythex.org/</a></p>

<p>Replacing the asterisk with a {3} says that you want 3 digits.</p>

<pre><code>.*?([0-9]{3})$
</code></pre>

<p>If you know your format will be close to the examples you showed, you can be a bit more explicit with the regex pattern to prevent even more accidental matches</p>

<pre><code>^.+_(\d{3})$
</code></pre>

python maya