title: Regex to replace characters that Windows doesn't accept in a filename
body: <p>I'm trying to build a regular expression that will detect any character that Windows does not accept as part of a file name (are these the same for other OS? I don't know, to be honest).</p>
  
  <p>These symbols are: </p>
  
  <pre> \ / : * ? "  | </pre>
  
  <p>Anyway, this is what I have: <code>[\\/:*?\"&lt;&gt;|]</code></p>
  
  <p>The tester over at <a href="http://gskinner.com/RegExr/" rel="noreferrer">http://gskinner.com/RegExr/</a> shows this to be working.
  For the string <code>Allo*ha</code>, the <code>*</code> symbol lights up, signalling it's been found. Should I enter <code>Allo**ha</code> however, only the first <code>*</code> will light up. So I think I need to modify this regex to find all appearances of the mentioned characters, but I'm not sure.</p>
  
  <p>You see, in Java, I'm lucky enough to have the function <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29" rel="noreferrer">String.replaceAll(String regex, String replacement)</a>.
  The description says: </p>
  
  <blockquote>
    <p>Replaces each substring of this string that matches the given regular expression with the given replacement.</p>
  </blockquote>
  
  <p>So in other words, even if the regex only finds the first and then stops searching, this function will still find them all.</p>
  
  <p>For instance: <code>String.replaceAll("[\\/:*?\"&lt;&gt;|]","")</code></p>
  
  <p>However, I don't feel like I can take that risk. So does anybody know how I can extend this?</p>