title: How can I replace all special characters in a URL, using a Java regular expression?
body: <p>I'm trying use regular expression to convert special characters in an url. Here's my sample code :</p>
  
  <pre><code>String formatUrl = "index.php?title=Test/enu/test/Tips_%26_Tricks/Tips_and_Tricks";
  formatUrl = formatUrl.replaceAll("[^a-zA-Z0-9]" , "-");
  </code></pre>
  
  <p>What I'm trying to do is to convert the special characters in the url such as ?_%. to "-" excluding "/".</p>
  
  <p>The regular expression in my code converts everything resulting the output as </p>
  
  <pre><code>index-php-title-Test-enu-test-Tips--26-Tricks-Tips-and-Tricks
  </code></pre>
  
  <p>But I want it to be </p>
  
  <pre><code>index-php-title-Test/enu/test/Tips--26-Tricks/Tips-and-Tricks
  </code></pre>
  
  <p>Any pointers will be appreciated.</p>