File & Path
Windows File Path
Matches absolute Windows file paths (e.g., C:\Users\file.txt).
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^[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
Related patterns
Unix File Path
File & PathMatches absolute Unix/Linux file paths.
Relative Path
File & PathMatches relative file paths (./, ../, or path/to/file).
File Extension
File & PathCaptures the file extension from a filename.
Image File Extension
File & PathMatch common image file extensions: jpg, jpeg, png, gif, webp, svg, avif, bmp, ico, tif, tiff.