title: Regex to validate a Windows UNC path
body: <p>I am trying to validate a Windows path in c# using a regex.  Based on this answer <a href="https://stackoverflow.com/a/24703223/4264336">https://stackoverflow.com/a/24703223/4264336</a> I have come up with a regex that allows drive letters &amp; unc paths but it seems to choke on spaces.</p>
  
  <p>The Function:</p>
  
  <pre><code>public bool ValidatePath(string path)
      {
          Regex regex = new Regex(@"^(([a-zA-Z]:\\)|\\\\)(((?![&lt;&gt;:""/\\|? *]).)+((?&lt;![ .])\\)?)*$");
          return regex.IsMatch(path);
      }
  </code></pre>
  
  <p>which works for all my test cases except the case where spaces are in the filename:</p>
  
  <pre><code>    [Test]
      [TestCase(@"c:\", true)]
      [TestCase(@"\\server\filename", true)]
      [TestCase(@"\\server\filename with space", true)] //fails
      [TestCase(@"\\server\filename\{token}\file", true)] 
      [TestCase(@"zzzzz", false)]
      public void BadPathTest(string path, bool expected) 
      {
          ValidatePath(path).Should().Be(expected);
      }
  </code></pre>
  
  <p>how do I get it to allow spaces in filenames,  I cant for the life of me see where to add it?</p>