title: Matching all three kinds of PHP comments with a regular expression
body: <p>I need to match all three types of comments that PHP might have:</p>
  <ul>
  <li><p><code># Single line comment</code></p>
  </li>
  <li><p><code>// Single line comment</code></p>
  </li>
  <li><p><code>/* Multi-line comments */</code></p>
  </li>
  <li><p> </p>
  <pre><code> /**
    * And all of its possible variations
    */
  </code></pre>
  </li>
  </ul>
  <p>Something I should mention: I am doing this in order to be able to recognize if a PHP closing tag (<code>?&gt;</code>) is inside a comment or not. If it is then ignore it, and if not then make it count as one. This is going to be used inside an XML document in order to improve <a href="https://en.wikipedia.org/wiki/Sublime_Text" rel="nofollow noreferrer">Sublime Text</a>'s recognition of the closing tag (because it's driving me nuts!). I tried to achieve this a couple of hours, but I wasn't able. How can I translate for it to work with XML?</p>
  <p>So if you could also include the if-then-else login I would really appreciate it. BTW, I really need it to be in pure regular expression expression, no language features or anything. :)</p>
  <p>Like Eicon reminded me, I need all of them to be able to match at the start of the line, or at the end of a piece of code, so I also need the following with all of them:</p>
  <pre><code>&lt;?php
      echo 'something'; # this is a comment
  ?&gt;
  </code></pre>