This is my current expression: https://regex101.com/r/BertHu/4/
^(?:(?:[a-z]:|\\\\[a-z0-9_.$●-]+\\[a-z0-9_.$●-]+)\\|\\?[^\\\/:*?"<>|\r\n]+\\?)*(?:[^\\\/:*?"<>|\r\n]+\\)*[^\\\/:*?"<>|\r\n]*$
The regular expression I'm using is based on this implementation from Oreilly.
Here's a breakdown (I had to fix some un-escaped characters from Oreilly's expression):
(?:(?:[a-z]:|\\\\[a-z0-9_.$\●-]+\\[a-z0-9_.$\●-]+)\\| # Drive
\\?[^\\\/:*?"<>|\r\n]+\\?) # Relative path
(?:[^\\\/:*?"<>|\r\n]+\\)* # Folder
[^\\\/:*?"<>|\r\n]* # File
I'm implementing this in PowerShell, and the expression will be case-insensitive.
The problem that I'm running into is that it's matching the following malformed path (and I'm sure more that are similar): C:\foo\C:\bar
I can't understand exactly why this is happening, but I believe it has something to do with the drive portion of the expression:
^(?:(?:[a-z]:|\\\\[a-z0-9_.$●-]+\\[a-z0-9_.$●-]+)\\|
I don't know how to exclude a second : from the above. Maybe I'm completely overlooking something obvious.
Any help at all would be tremendously appreciated as I've spent all day working on this expression.
Thanks much.
