Unix and Windows live differently
Unix paths use /; Windows uses \ (with various escapes) AND / (modern Windows accepts both). Regex for both is awkward. Use your language's path library when you can.
Common patterns
Match a Unix-style path:
(?:/?[\w.-]+)+/?
Match a filename with extension:
([\w-]+)\.(\w+)$
Match an extension only (after the last dot):
\.([^.]+)$
Match all paths in a string:
(?:\./|/|~/)[\w./-]+
Starts with ./, /, or ~/; followed by path-friendly characters.
Replace your manual splitting with the library
Python pathlib.Path gives you .name, .stem, .suffix, .parent, .parts — no regex needed.
Same in JS (path module), Go (path/filepath). Reach for the library for actual path manipulation. Regex is only for finding path-shaped substrings in larger text.