如果我有这种格式的字符串:
string placeholder = "[[Ford:Focus(blue)]]";
我可以用什么正则表达式来填充下面的三个变量?
string make = ?
string model = ?
string colour = ?
有什么想法吗?
谢谢,
答案 0 :(得分:1)
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;
....