split string with regex into three separate variables

后端 未结 1 1568
北恋
北恋 2021-01-25 21:05

If I have a string in this format:

string placeholder = \"[[Ford:Focus(blue)]]\";

What regex could I use to populate the three variables below?

相关标签:
1条回答
  • 2021-01-25 21:54
    string input = "[[Ford:Focus(blue)]]";
    var parts = Regex.Matches(input, @"\w+").Cast<Match>().Select(x => x.Value).ToList();
    
    var make = parts[0];
    ....
    

    OR

    var match = Regex.Match(input, @"\[\[(\w+):(\w+)\((\w+)\)\]\]");
    var make = match.Groups[1].Value;
    var model = match.Groups[2].Value;
    ....
    
    0 讨论(0)
提交回复
热议问题