tags:

views:

51

answers:

2

I used the following

Regex RE = new Regex(@"'?([(\.\//\s\;\,\:\.\)]+)'?");

to split the expression which is stored in an xml file.

"NIGHT.set('/xs:Service/xs:Location[2]/xs:Res/protocol','HOPR','SP')";

It craps out when reading it, because of the single quotes. I want to get rid of the single quotes in the xml file, changing the expression to,

"NIGHT.set(/xs:Service/xs:Location[2]/xs:Res/protocol,HOPR,SP)";

but when I try the regexp again, it mostly works, but has a entry in split block after applying the regexp of "(\"

So its not doing it right. I'm pretty crap at regexp, so can anybody quickly show me how to change it for the better.

Thanks. scope_creep

+1  A: 

Have you tried regex coach? It's a really handy tool for solving these sort of problems.

Adrian Grigore
I give it a try. I did try regexbuddy, but at the time, didn't have the time to go through it.
scope_creep
A: 

This is one way you could do it:

    string s = "NIGHT.set('/xs:Service/xs:Location[2]/xs:Res/protocol','HOPR','SP')";
    s = s.Replace("'", "");
    Regex re = new Regex(@"^(.*)\((.*)\)$");
    Match match = re.Match(s);
    if (match.Success)
    {
        string function = match.Groups[1].Value;
        string[] parameters = match.Groups[2].Value.Split(',');
        // ...
    }
Mark Byers
I need to get the 3 expressions out, plus the NIGHT.set. The expressions drive a set of rule.
scope_creep
OK, perhaps you should add that info to the question, because it's not at all clear.
Mark Byers
I've updated my answer based on your reply.
Mark Byers
Thanks Mark.Bob.
scope_creep