title: JavaScript RegExp.test() returns false, even though it should return true
body: <p>The Prob: I get an AJAX response (JSON or plaintext with line breaks). Each item of the response should be checked via RegEx to find out whether it matches to user-definded patter or not.</p>
  
  <p>Example:</p>
  
  <p>Ajax Response (plain-text)</p>
  
  <pre><code>"Aldor
  Aleph
  Algae
  Algo
  Algol
  Alma-0
  Alphard
  Altran"
  </code></pre>
  
  <p>User-pattern:</p>
  
  <pre><code>/^Alg/ig.test(responseItem)
  </code></pre>
  
  <p>RegExp Results should look like:</p>
  
  <pre><code>Aldor   // false
  Aleph   // false
  Algae   // true
  Algo    // true
  Algol   // true
  Alma-0  // false
  Alphard // false
  Altran  // false
  </code></pre>
  
  <p>But each time i get different (and kinda weired) results... e.g. (<code>/^alg/ig.test("Algo")</code> => <strong>false</strong>)</p>
  
  <p>My code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>...
  &lt;form&gt;
    &lt;input id="in" /&gt;
  &lt;/form&gt;
  &lt;div id="x"&gt;
    Aldor
    Aleph
    Algae
    Algo
    Algol
    Alma-0
    Alphard
    Altran
  &lt;/div&gt;&lt;button id="checker"&gt;check!&lt;/button&gt;
  ...
  </code></pre>
  
  <p><strong>JavaScript (jQuery 1.6.2)</strong></p>
  
  <pre><code>$(function(){
      var $checker = $('#checker');
  
      $checker.click(function(ev){
          var inputFieldVal = $.trim($('#in').val());
          console.log(inputFieldVal); // Alg
          var regExpPattern = '^'+inputFieldVal,
              re = new RegExp(regExpPattern, 'igm');
          onsole.log(re); // /^Al/gim
          // Get text out of div#x
          var text = $('#x').text();
          // Trim and 'convert' to an array...
              text = $.trim(text).split('\n');
          console.log(text); // ["Aldor", "Aleph", "Algae", "Algo", "Algol", "Alma-0", "Alphard", "Altran"]
  
          for (var index=0, upper=text.length;index&lt;upper;++index) {
              console.log(
                 re.test(text[index]),
                 text[index]
               );
          }
      });
  })
  </code></pre>
  
  <p><strong>Console OUTPUT:</strong></p>
  
  <p><code>/^Alg/ig</code> => should match each item which starts with <code>Alg</code></p>
  
  <pre><code>false "Aldor"
  false "Aleph"
  true "Algae"
  false "Algo" //Why ? O.o
  true "Algol"
  false "Alma-0"
  false "Alphard"
  false "Altran"
  </code></pre>
  
  <p><code>/^Al/ig</code> => should match each item because every item start with <code>Al</code></p>
  
  <pre><code>true "Aldor"
  false "Aleph" //Why ? O.o
  true "Algae"
  false "Algo" //Why ? O.o
  true "Algol"
  false "Alma-0" //Why ? O.o
  true "Alphard"
  false "Altran" //Why ? O.o
  </code></pre>
  
  <p>Any suggestions?</p>