字典添加配套項目從查詢字符串字典添加匹配字符串的項目從查詢字符串
更改爲MyQuery = "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;
}