当您到达 KeyC 时,我不太确定您在寻找什么。您如何知道 KeyB 的字符串值何时结束而 KeyC 的字符串何时开始?'this\'s is a string' 或换行符后是否有冒号?这是一个让您入门的示例:
[TestMethod]
public void SplitString()
{
string splitMe = "KeyA : SubComponent { SubKey : SubValue } KeyB:This's is a string";
string pattern = "^(.*):(.*)({.*})(.*):(.*)";
Match match = Regex.Match(splitMe, pattern);
Assert.IsTrue(match.Success);
Assert.AreEqual(6, match.Groups.Count); // 1st group is the entire match
Assert.AreEqual("KeyA", match.Groups[1].Value.Trim());
Assert.AreEqual("SubComponent", match.Groups[2].Value.Trim());
Assert.AreEqual("{ SubKey : SubValue }", match.Groups[3].Value.Trim());
Assert.AreEqual("KeyB", match.Groups[4].Value.Trim());
Assert.AreEqual("This's is a string", match.Groups[5].Value.Trim());
}