Skip to main content
Regexflux

Windows File Path

beginner

Matches Windows file paths with drive letter.

filepathwindowsvalidation

Pattern

/[A-Za-z]:\\(?:[\w.-]+\\)*[\w.-]+/g

Try It

0 of 5 strings matched

Explanation

Matches a drive letter (A-Z) followed by :\ and backslash-separated path components.

Test Strings

Matching

  • C:\Users\John\file.txt
  • D:\Projects\src\main.ts

Non-matching

  • /home/user/file.txt
  • C:/path/file
  • \\server\share

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /[A-Za-z]:\\(?:[\w.-]+\\)*[\w.-]+/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

UNC path

\\\\[\w.-]+(?:\\[\w.-]+)+

Matches UNC network paths like \\server\share\file

Related Patterns