Extracting capital letters ( English ) | Preferred method
<p>Given a string of text</p>

<pre><code>var string1 = 'IAmNotFoo';
</code></pre>

<p>How do you extract just the capital letters?</p>

<pre><code>'IANF'
</code></pre>

<p>Here are some methods per links below:</p>

<pre><code>function isUpperCase1(aCharacter) {    
    if ( ch == ch.toUpperCase() ) {
        return true;
    }
    return false;
}

function isUpperCase2( aCharacter ) {    
    return ( aCharacter &gt;= 'A' ) &amp;&amp; ( aCharacter &lt;= 'Z' );
}

var string1 = 'IAmNotFoo',
    string2 = '',
    i = 0,
    ch = '';

while ( i &lt;= string1.length ) {
    ch = string1.charAt( i );
    if (!isNaN( ch * 1 ) ) {
        alert('character is numeric'); 
    }
    else if ( isUpperCase2() ) { // or isUpperCase1
        string2 += ch;
    }
    i++;
}
</code></pre>

<p>or simply ( per comment below ):</p>

<pre><code>var upper = str.replace(/[^A-Z]/g, '');
</code></pre>

<p><strong>SO Related</strong></p>

<p><a href="http://stackoverflow.com/questions/6055152/finding-uppercase-characters-within-a-string">Finding uppercase characters within a string</a></p>

<p><a href="http://stackoverflow.com/questions/1027224/how-can-i-test-if-a-letter-in-a-string-is-uppercase-or-lowercase-using-javascrip">How can I test if a letter in a string is uppercase or lowercase using JavaScript?</a></p>
