字典添加配套项目从查询字符串字典添加匹配字符串的项目从查询字符串
更改为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;
}