我从RegexLibrary中找到了以下模式,但我不知道如何使用 Match 来获取 Re 和 Im 值。我是新来的Regex
。这是从模式中获取数据的正确方法吗?如果是真的,我需要一些示例代码!这就是我认为应该的:
public static complex Parse(string s)
{
string pattern = @"([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?|[-+]?((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?[i]|[-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?[-+]((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?[i])";
Match res = Regex.Match(s, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
// What should i do here? The complex number constructor is complex(double Re, double Im);
// on error...
return complex.Zero;
}
提前致谢!