 <p>Try the following:</p> <pre><code> var parts = table_id.split('_'); var num = parts[1]; // it would be the number you want </code></pre> <p>For more detail on <code>split()</code> check <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split" rel="nofollow">this link</a></p> <p>Or you may try the following:</p> <pre><code>var regex = /.*_(\d+)/; var num = table_id.replace(regex, '$1') </code></pre>