Regex to Match a Windows File Path
Copy the pattern, paste text below, and watch it highlight every Windows path. Below the tester: how the drive letter and folder segments are matched.
What this pattern matches
This matches an absolute Windows path that starts with a drive letter, followed by backslash-separated folders and an optional file name.
How it works, part by part
[A-Za-z]: — a drive letter and colon, like C:.
\\ — the leading backslash after the drive.
(?:[^\\/:*?"<>|\r\n]+\\)* — zero or more folder names, each followed by a backslash. The character class excludes characters Windows forbids in names.
[^\\/:*?"<>|\r\n]* — the final file or folder name.
UNC and Unix paths
This does not match UNC paths (\\server\share) or Unix paths (/home/jane). Those need their own patterns.
FAQ
Does it match UNC paths like \\server\share?
No. This matches drive-letter paths only. UNC paths need a separate pattern that allows a double-backslash start.
Does it reject invalid filename characters?
Yes. The character class excludes the characters Windows forbids in names, such as * ? < > and |.