Donate

Match Network Path In A String Using Regular Expression

Hello,

While working on a project, I was confronted with an issue on how to match or extract a network path. Normally, you can use string functions or built-in .NET code to check the validity of a path, but since I'm also refreshing my skills in Regular Expression. I prefer the latter as the solution. So the pattern to match the server path is presented below:
((\\\\)?((?<Folder>[a-zA-Z0-9- _]+)(\\.*[a-zA-Z0-9-_ \\])(?=")))
And to declare that pattern in your C# code, you have to escape the back slash characters.
string ServerPath = "((\\\\\\\\)?((?<Folder>[a-zA-Z0-9- _]+)(\\\\.*[a-zA-Z0-9-_ \\\\])(?=\")))";
The input strings tested are as follows.
Const ImagesPath As String = "\\ImagesServer\Logo Files\InetPub\TempProjects\"
Const docsPath As String = "\\docsPathServer15\Health\Physicians\"
Const vsPath As String = "\\vsServer909\vs2017\Projects"
string manual = "\\manualServer\CompanyRules\EmployeeFiles\Cebu"; 
The referenced post is here: Pattern Matching Path Files but I made some modifications to get the path inside the enclosing quotes.

Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input