title: JavaScript RegExp: Different results: Built pattern using string & using regexp "literal"?
body: <p>Is there any differences between using RegExp literals vs strings?</p>
  
  <p><a href="http://jsfiddle.net/yMMrk/" rel="nofollow">http://jsfiddle.net/yMMrk/</a></p>
  
  <pre><code>String.prototype.lastIndexOf = function(pattern) {
      pattern = pattern + "(?![\s\S]*" + pattern + ")";
      var match = this.match(pattern);
      return (match == null) ? -1 : match.index;
  }
  
  function indexOfLastNewline(str) {
      var match = str.match(/\r?\n(?![\s\S]*(\r?\n))/);
      return (match == null) ? -1 : match.index;
  }
  
  var str = "Hello 1\nHello 2\nHello 3\nHello4";
  alert(str.lastIndexOf("(\r?\n)")); // always returns the 1st newline (7)
  alert(indexOfLastNewline(str)); // returns correctly (23)
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>even if I use a <code>RegExp</code> object, I still get the same result</p>
  
  <p><a href="http://jsfiddle.net/yMMrk/2/" rel="nofollow">http://jsfiddle.net/yMMrk/2/</a> </p>