title: Regex to capture single line comment
body: <p>Using regular expression in java, I want to detect single line JS comment that starts with <b>//</b>. So what I come up with is -</p>
  
  <pre><code>[^:]\/\/.*$
  </code></pre>
  
  <p>Above regular expression is not capturing : </p>
  
  <pre><code>http://example.com
  </code></pre>
  
  <p>But its capturing highligted portion from following String (I can understand why) : ab<b>c//qqqqqqqqqq
  </b>. But I don't want c (character immediate left to //) to be captured.</p>
  
  <p>Also, I dont want below strings to be captured at all : </p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
  &lt;%//Table for help essages ends%&gt;  
  </code></pre>
  
  <p>I know, this topic is diccused multiple times. But nothing is helping me much. So I am asking this question again. For testing purpose I'm using <a href="http://rubular.com/" rel="nofollow">http://rubular.com/</a> this site.</p>
  
  <p>Can anyone please help me.</p>
  
  <p><b>Solution : </b></p>
  
  <pre><code>(?&lt;!http:|https:)\/\/.*(?&lt;!&gt;)\s$
  </code></pre>
  
  <p>To remove other type of comments we are using :</p>
  
  <pre><code>&lt;!--(.|\s)*?--&gt;
  \/\*(.|\s)*?\*\/
  &lt;%--(.|\s)*?--%&gt;
  </code></pre>
  
  <p><b>Test Case : </b></p>
  
  <pre><code>http://example.com
  abc  //  qqqqqq&gt;qqqq 
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;   
  &lt;% // END: Modified for Bug # 1070 %&gt;
  
  // comment
  /* comment */ program //comment
  
  
  var ok = "not really"; 
  // This is a comment
  // Shouldn't this be a comment too?
  
  var one = 't "stuff"\' now.'; // comment /* hola */ // lol
  
  /* multiline comment
  // still
  /* still * * * * / */
  something here
  
  'string\' // string'; // comment /* comment
  /regex/; // comment */* still-a-comment
  ' /**/ string ' /* "comment..."
  // still-a-comment */ alert('isn\'t a comment!');
  /\/* this isn't a comment! */; //* comment
  /*
      //a comment... // still-a-comment
      12345
      "Foo /bar/ ""
  */
  /*//Boo*/
  /*/**/
  </code></pre>