I am using C# and Visual Studio 2010. I'm just trying to match a string (which is a path in this case) and create a pattern that will help me figure out if it's a valid pattern or not. The below examples are made up arbitary ones, but they do contain
So I am trying to create a pattern that will match a UNC path which is coming in as a string. For example:
"\\\\Apple-butter27\\AliceFakePlace\\SomeDay\\Grand100\\Some File Name Stuff\\Yes these are fake words\\One more for fun2000343\\myText.txt"
Above is an example of a file path I'm trying to pattern match. I'm attempting to match it with this pattern:
@"\\\\[a-zA-Z0-9-]+\\\w+\\\w+\\\w+\\((\w+)*(\s+)*)*\\((\w+)*(\s+)*)*\\((\w+)*(\s+)*)*\\w+\.txt";
The thing I am guarenteed is there will be 7 folders until I reach my file(s). I'll have to look for a combo of spaces, letters, and numbers for pretty much all the segments.
I did try starting by matching small bits such as my first iteration of testing I tried this as my pattern:
@"\\\\";
And this works since it'll match the first few characters, but if I add this to it:
@"\\\\[a-zA-Z0-9-]+";
It fails. So I thought maybe it was since the strings are causing it to double up so I may have to double my "\" so I tried it again with 8 "\" alone, but that failed.
My goal with previous pattern is to match "\\\\Apple-butter27"
I've been looking on google and all over this site, but none of the pattern matching UNC stuff I found is quite my issue.
I'd really appreciate it if someone could tell me what I'm doing wrong with this pattern. At least a starting point since I know it's a long and probably is going to be a really complicated one...but if someone could point out general things that are wrong with it.
Though since it's a path in non-string state it looks like this:
\\Apple-butter27\AliceFakePlace\SomeDay\Grand100\Some File Name Stuff\Yes these are fake words\One more for fun2000343\myText.txt
I'm new to attempting pattern matching with UNC paths so it's starting to really confuse me so if someone can light the way, I'd appreciate it a lot.
I'm using the .Success function of Regex to see if the patterns match and I'm simply printing a message if the match was success or failure. My main focus is the pattern unless there's some good insight on working with the path as something other than a string for a solution.