Search code examples
c#regexregular-language

create a regular expression of a specific sentence


I am using a constraint file for my system and basically i am using this line for parsing my values:

angle(Vector(JointA,jointB),Vector(JointA,jointB),minValue,maxValue)

Can you please help me and specify the regular expression of this line. I want to be able to retrieve the names of the four joints, including the minValue as well as the maxValue. Thanks!


Solution

  • If you're just asking for a way to parse the variable bits from this kind of text, it's quite easy:

    See here: http://tinyurl.com/qjdaj9w

    var exp = new Regex(@"angle\(Vector\((.*?),(.*?)\),Vector\((.*?),(.*?)\),(.*?),(.*?)\)");
    
    var match = exp.Match("angle(Vector(JointA,jointB),Vector(JointA,jointB),minValue,maxValue)");
    
    
    var jointA1 = match.Groups[0];
    var jointB1 = match.Groups[1];
    var jointA2 = match.Groups[2];
    var jointB2 = match.Groups[3];
    var max     = match.Groups[4];
    var min     = match.Groups[5];