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;
}
前もって感謝します!