File & Path
Windows File Path
Matches absolute Windows file paths (e.g., C:\Users\file.txt).
Try it in RegexProPattern
regexJavaScript
/^[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/Raw source: ^[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$
How it works
`^[A-Za-z]:\\` matches the drive letter and root backslash. `(?:[^\\/:*?"<>|\r\n]+\\)*` matches directory segments. Final segment (the file or folder name) is allowed to be empty.
Examples
Input
C:\Users\John\file.txtMatches
C:\Users\John\file.txt
Input
D:\Matches
D:\
Input
/unix/pathNo match
—Common use cases
- Cross-platform tools
- File pickers
- Path validation