.NET solution — speculative
This suggested .NET solution is just 'suggested'; I don't do .NET and have no way of testing it on any of my machines (is there a regex-test web site for .NET?). I've taken the working Perl solution, removed the <mark> and <pad> parts that you're not worried about, and the comments, and flattened it all onto one line on the assumption that .NET doesn't have an option for legibility analogous to Perl's x option. You can still find 5 sets of parentheses corresponding to the 5 parts of the Perl regex. I'm assuming that (?:...) is a non-capturing group.
(?:-{1,2}|/)(?<name>\w+)(?:[=:]?|\s+)(?<value>[^-\s"][^"]*?|"[^"]*")?(?=\s+[-/]|$)
I also assume that .NET provides some mechanism analogous to Perl's g modifier that allows you to scan the string on a second (or subsequent) pass where it left off on the previous pass. Or that you can somehow determine where the end of the match was and resume the scan from there.
Perl solution — validated
This is as good as I've managed to come up with using Perl regexes (tested with Perl 5.16.0 on Mac OS X 10.7.5).
#!/usr/bin/env perl
use strict;
use warnings;
# Original regex split into 5 sections:
# C1 (?<=(^-{1,2}|\ -{1,2}|^/|\ /))
# C2 (?<name>[\w]+)
# C3 [ :"]*
# C4 (?<value>[\w.?=&+ :/|\\]*)
# C5 (?=[ "]|$)
my $rx = qr%(?<mark> -{1,2}|/ ) (?# Was C1)
(?<name> \w+ ) (?# Was C2)
(?<pad> (?: [=:]?|\s+ )) (?# Was C3)
(?<value> (?: [^-\s"][^"]*? | "[^"]*" ))? (?# Was C4)
(?=\s+[-/]|$) (?# Was C5)
%x;
while (my $line = <DATA>)
{
chomp $line;
print "\nLine: $line\n";
while ($line =~ m/$rx/g)
{
my($mark, $name, $pad, $value) = ($1, $2, $3, $4 // "");
print "Found: mark $mark name <<$name>> pad <<$pad>> value <<$value>>\n";
}
}
__DATA__
-s -i:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
-o:"C:\temp\db\" -s -r -host:localhost --d theDB
-s -i:"C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB -Scripts\" -h:localhost -d:theDB
-s -d http://www.theproject.com -h:localhost -d:theDB
-i:"C:\Users\Fozzie\Workspace\TheProject\TheProject_Stack_1_5\db\DB Scripts\" --h:localhost -d:theDB
-h:localhost -i:"C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack_1_5\db\DB Scripts\" -d:theDB
--d theDB -o:"C:\temp\db\" -host=local-host -r
-s -i:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
/d theDB /o:"C:\temp\db\" /host=local-host /r
/d theDB /o:"C:\temp\db\" /host=local-host /r /t
-s:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
The bulk of the script is not very interesting. The outer while loop reads the data section of the file (which is the material after the marker __DATA__) one line at a time, prints it for validation, then repeatedly runs the regex on the line to find the components (the marker, the name, the padding, and the value), printing those out. The bulk of the data is what was provided in the question (thank you!). The last three lines of the data are extra compared to what was originally provided.
All the excitement is in the regex. I've used Perl's /x modifier to allow white space in the regex for readability. This means that white space is not significant unless preceded by a backslash or enclosed in square brackets (and there is no significant white space in this specimen). I've used the (?<name> ...) notation to identify the pieces as in the original, though the names could be omitted since they aren't used. The (?# Was Cn) parts are pure comment.
- The mark is either one or two dashes or a slash;
--? would be another, shorter way to write it.
- The name is a string of alphanumerics; this does not attempt to enforce 'first character may not be a digit'.
- The pad separates the name from the value. It can be a single equals or colon, or a string of white space. The inner
(?: ...) is a non-capturing grouping operator.
- The value is optional (the
-s option in the first position of the first line of the sample data doesn't have a value). It consists of: either a string starting with something other than a dash, double quote or white space, followed by a non-greedy string of non-quotes; or a double quote, a string of non-quotes, and another double quote.
- The trailing zero-width context (C5) is either one or more white space characters followed by a dash or slash, or EOS. Because the value pattern is non-greedy, the greedy trailing context gobbles the trailing white space after an option value.
The output is:
Line: -s -i:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
Found: mark - name <<s>> pad << >> value <<>>
Found: mark - name <<i>> pad <<:>> value <<C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\>>
Found: mark - name <<h>> pad <<:>> value <<local:host>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: -o:"C:\temp\db\" -s -r -host:localhost --d theDB
Found: mark - name <<o>> pad <<:>> value <<"C:\temp\db\">>
Found: mark - name <<s>> pad <<>> value <<>>
Found: mark - name <<r>> pad <<>> value <<>>
Found: mark - name <<host>> pad <<:>> value <<localhost>>
Found: mark -- name <<d>> pad << >> value <<theDB>>
Line: -s -i:"C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB -Scripts\" -h:localhost -d:theDB
Found: mark - name <<s>> pad << >> value <<>>
Found: mark - name <<i>> pad <<:>> value <<"C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB -Scripts\">>
Found: mark - name <<h>> pad <<:>> value <<localhost>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: -s -d http://www.theproject.com -h:localhost -d:theDB
Found: mark - name <<s>> pad << >> value <<>>
Found: mark - name <<d>> pad << >> value <<http://www.theproject.com>>
Found: mark - name <<h>> pad <<:>> value <<localhost>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: -i:"C:\Users\Fozzie\Workspace\TheProject\TheProject_Stack_1_5\db\DB Scripts\" --h:localhost -d:theDB
Found: mark - name <<i>> pad <<:>> value <<"C:\Users\Fozzie\Workspace\TheProject\TheProject_Stack_1_5\db\DB Scripts\">>
Found: mark -- name <<h>> pad <<:>> value <<localhost>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: -h:localhost -i:"C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack_1_5\db\DB Scripts\" -d:theDB
Found: mark - name <<h>> pad <<:>> value <<localhost>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: --d theDB -o:"C:\temp\db\" -host=local-host -r
Found: mark -- name <<d>> pad << >> value <<theDB>>
Found: mark - name <<o>> pad <<:>> value <<"C:\temp\db\">>
Found: mark - name <<host>> pad <<=>> value <<local-host>>
Found: mark - name <<r>> pad <<>> value <<>>
Line: -s -i:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
Found: mark - name <<s>> pad <<>> value <<>>
Found: mark - name <<i>> pad <<:>> value <<C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\>>
Found: mark - name <<h>> pad <<:>> value <<local:host>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
Line: /d theDB /o:"C:\temp\db\" /host=local-host /r
Found: mark / name <<d>> pad << >> value <<theDB >>
Found: mark / name <<o>> pad <<:>> value <<"C:\temp\db\">>
Found: mark / name <<host>> pad <<=>> value <<local-host >>
Found: mark / name <<r>> pad <<>> value <<>>
Line: /d theDB /o:"C:\temp\db\" /host=local-host /r /t
Found: mark / name <<d>> pad << >> value <<theDB>>
Found: mark / name <<o>> pad <<:>> value <<"C:\temp\db\">>
Found: mark / name <<host>> pad <<=>> value <<local-host>>
Found: mark / name <<r>> pad <<>> value <<>>
Found: mark / name <<t>> pad <<>> value <<>>
Line: -s:C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\ -h:local:host -d:theDB
Found: mark - name <<s>> pad <<:>> value <<C:\Users\Fozzie\Workspace\TheProject\TheProject-Stack-1_5\db\DB Scripts\>>
Found: mark - name <<h>> pad <<:>> value <<local:host>>
Found: mark - name <<d>> pad <<:>> value <<theDB>>
-i:end, and how do you know that? It looks to me likeScripts\is a loose word on its own; is that correct? Or does the argument continue until the next blank followed by dash (or end of string)?(?<=(^-{1,2}| -{1,2}|^/| /))). So, which sub-species of RE are you targetting? Which language supports the variable-width look-behind? (Also, none of your sample data uses the/-as-option-introducer notation that you seem to be supporting.)