Regular expression problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



I'm attempting my first regular expression (ok, I nicked some of it from a
blog) and I'm not seeing the results I expect to see. Given that it does not
work, I find myself entirely stuck. Can you help?

I'm trying to split command line parameters specified in the format:
/Startup /Model=a /view="b" /entity="/c"

Where all command line parameters start with a forward slash. They may or
may not have values following an equals sign (I plan to use a variation of
this regex to split key/value pairs) which may also contain a forward slash
(enclosed in quotes), so I need to ignore these in the split.

The code I am using to split the string is:

Regex rex = new
Regex("/(?=([^\\\"]*\\\"[^\\\"]*\\\")*(?![^\\\"]*\\\"))");
string[] values = rex.Split(strCommand);
foreach (string val in values)
System.Windows.Forms.MessageBox.Show(val);

The results I get are strange:
<blank line>
/entity="/c"
startup
/entity="/c"
model=a
/entity="/c"
view="b"
entity="/c"
entity="/c"

I think it has something to do with capturing groups being included in the
string array, but don't know how to detect this and remove them.I ran the
code through a regular expression test app (RegexBudy) and that correctly
identified the delimiters, so I guess the expression itself is correct. I
guess I'm interpreting the output wrongly.

Any suggestions ?

Thanks
Steve


.



Relevant Pages

  • Re: Get regular expression
    ... own tree structure. ... Expression compares a string character-by character, ... regular expression solution, which was about as close as one could get to ... the structure of the hierarchy can be inferred by using ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Get regular expression
    ... regular expression solution, which was about as close as one could get to ... first string. ... explode "ABLATION" and see subnodes of "ENDOMETRIAL ... "Heart 27.33/2" ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regular expression optimization
    ... position in the replacement array of strings, ... > input string and a MatchEvaluator delegate. ... > The first part required combining the separate Regular Expression strings ...
    (microsoft.public.dotnet.general)
  • Small regular expression parser
    ... the goal was to develop a very simple regular expression parser. ... sets are selected using the % character instead of \. ... into the string of the start of the match and the length of the match. ... Last there are a couple macros to help with captures. ...
    (comp.lang.lisp)
  • Re: Which RegEx Testing Tool Do You Prefer?
    ... * Regular Expression Tester ... > match has been returned prior to the end of the string. ... >> a white space although in a manner that is confusing as I will point out ... >> would ignore those previous white space characters and then report 2:? ...
    (microsoft.public.dotnet.framework.aspnet)