StringCollection resultList = new StringCollection();
try {
Regex regexObj = new Regex(@"(([a-z]:|\\\\[a-z0-9_.$]+\\[a-z0-9_.$]+)?(\\?(?:[^\\/:*?""<>|\r\n]+\\)+)[^\\/:*?""<>|\r\n]+)");
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success) {
resultList.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
Breakdown :
@"
( # Match the regular expression below and capture its match into backreference number 1
( # Match the regular expression below and capture its match into backreference number 2
| # Match either the regular expression below (attempting the next alternative only if this one fails)
[a-z] # Match a single character in the range between “a” and “z”
: # Match the character “:” literally
| # Or match regular expression number 2 below (the entire group fails if this one fails to match)
\\ # Match the character “\” literally
\\ # Match the character “\” literally
[a-z0-9_.$] # Match a single character present in the list below
# A character in the range between “a” and “z”
# A character in the range between “0” and “9”
# One of the characters “_.$”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\\ # Match the character “\” literally
[a-z0-9_.$] # Match a single character present in the list below
# A character in the range between “a” and “z”
# A character in the range between “0” and “9”
# One of the characters “_.$”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)? # Between zero and one times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 3
\\ # Match the character “\” literally
? # Between zero and one times, as many times as possible, giving back as needed (greedy)
(?: # Match the regular expression below
[^\\/:*?""<>|\r\n] # Match a single character NOT present in the list below
# A \ character
# One of the characters “/:*?""<>|”
# A carriage return character
# A line feed character
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\\ # Match the character “\” literally
)+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
[^\\/:*?""<>|\r\n] # Match a single character NOT present in the list below
# A \ character
# One of the characters “/:*?""<>|”
# A carriage return character
# A line feed character
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
"