クエリ文字列から辞書に一致する項目を追加します
マイクエリ ="RecordFiles/findrecords/$filter=userid eq 8w4W4E and recordid eq 1catf2deb-4wdx-450c-97cd-6rre331d4a6ec";
文字列 myRegexQueryPattern =@"^(RecordFiles/findrecords/\$filter=userid eq)\s(?<userid>\S+)((\s(and recordid eq)\s(?<recordid>\w+))|())";
Dictionary<string, string> dataDictionary;
Regex myregx = new Regex(myRegexQueryPattern, RegexOptions.IgnoreCase);
bool status= AddToDictionary(myQuery, myregx, out dataDictionary);
しかし、このコードを実行すると、recordid の最初の部分だけが取得され、残りはスキップされます。
実結果
recordid=1catf2deb
期待される結果 ここに私の辞書が含まれている必要があります
recordid =1catf2deb-4wdx-450c-97cd-6rre331d4a6ec
期待される結果を得るために誰かが助けてくれますか?コードのどの部分が間違っているのか、どのようにコードを修正して期待される結果を得ることができますか?
public static bool AddToDictionary(string query, Regex regex, out Dictionary<string, string> data)
{
Match match = regex.Match(query);
bool status = false;
string[] groupNames = regex.GetGroupNames();
data = new Dictionary<string, string>();
if (match.Success)
{
foreach (var groupName in groupNames)
{
data.Add(groupName, match.Groups[groupName].Value);
}
status = true;
}
return status;
}