title: Javascript replace regular expression not working as expected?
body: <p>I have the following routine to replace the Time portion of a datetime string displayed in the options of a drop down list called "SalesWeek". The Replace method is not replacing the the portion of the string the regular expression is expected to match.  </p>
  
  <p>When the following routine runs in the browser (FF):</p>
  
  <pre><code>var select = $('#SalesWeek');
  var item = '';
  
  $.each($('#SalesWeek option'), function(){
      item = $(this).text();
      console.log('before: ' + item);
      var regex = new RegExp(/(\s([0]\d|[1][0-2])(\:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})/);
      item.replace(regex,'');
      console.log('after: ' + item);
      $(this).html(item);
  });
  </code></pre>
  
  <p>The following is printed to the console:</p>
  
  <pre><code>before: 12/31/2011 12:00:00 AM
  after: 12/31/2011 12:00:00 AM
  </code></pre>
  
  <p>But I'm expecting:</p>
  
  <pre><code>before: 12/31/2011 12:00:00 AM
  after: 12/31/2011
  </code></pre>
  
  <p>I've tried using $(this).html() and $(this).text() to get the initial value thinking perhaps there are characters I'm just not seeing in the console for either case...but it doesn't seem to make a difference.</p>
  
  <p>I've tested the regular expression for use in javascript at the following link:
  <a href="http://www.regxlib.com/RETester.aspx" rel="nofollow">http://www.regxlib.com/RETester.aspx</a></p>
  
  <p><strong>Using javascript engine</strong></p>
  
  <pre><code>Test Expression: (\s([0]\d|[1][0-2])(\:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})
  Input Value: 12/3/2011 12:00:00 AM
  Expected Match: 12:00:00 AM
  </code></pre>
  
  <p>It appears to work without issue.  Notice that I stripped the leading "/" and trailing "/" on the expression when testing, but I believe the "/" is necessary when creating the new RegExp in javascript.  Perhaps I'm wrong about that and there's another way, but I seem to get an error in firebug if the expression I'm trying to create is not enclosed that way.</p>
  
  <p>I always seem to find answers I'm searching for on Stack Overflow to most issues I encounter...but I'm at a loss...so, I'm humbled enough to be the one asking the question this time...any help is very much appreciated...</p>