title: deleting all text except what matches regex java
body: <p>I have regexp, that should delete comments(ye, it's bad, but for me it works)</p>
  
  <pre><code>String regex = (^\/\/.*)|(\s+\/\/.*)|((\/\*)(.|\n)+?(\*\/));
  </code></pre>
  
  <p>this code should delete all commtents</p>
  
  <pre><code>Pattern.compile(regex).matcher(some text).replaceAll(" ");
  </code></pre>
  
  <p>but how can i make it to delete all EXCEPT regexp?</p>
  
  <p>For example:
  if i have string like this:</p>
  
  <p><code>/*Comments it's cool*/
  public static void foo(){}</code></p>
  
  <p>my regexp match comments, but i need to delete what doesn't match, so it will look like:</p>
  
  <pre><code>/*Comments it's cool*/
  </code></pre>