我有下面的正则表达式,它匹配第三个参数为“null”或“string.empty”的函数“searchresult”:
^(.*\.)?searchresult\((?:[^,]*,){2}\s*(null|string\.Empty)\s*(?:,[^,]*){2}\);
正则表达式不应与以下行匹配
errorList.Add(new Microsoft.Practices.EnterpriseLibrary.Validation.searchresult("[Validation_MaxLength_ErrorMessage_2000]", staffonlineInquiry, "onlineInquiryResponseInformation", string.Empty, null));
searchresult error = new searchresult("[Validation_notwellLeavecheckReturnToWorkDateYes_ErrorMessage]|[Label_IsnotwellLeavecheckReturnToWorkDate_Text]", target, "notwellLeavecheckReturnToWorkDate", null, null);
正则表达式应与以下行匹配
errorList.Add(new Microsoft.Practices.EnterpriseLibrary.Validation.searchresult("[Validation_MaxLength_ErrorMessage_2000]", enquiry, null, string.Empty, null));
searchresult error = new searchresult("[Validation_notwellLeavecheckReturnToWorkDateYes_ErrorMessage]|[Label_IsnotwellLeavecheckReturnToWorkDate_Text]", target, string.Empty, null, null);
1条答案
按热度按时间s4n0splo1#
正则表达式给出了问题前三行的预期结果,第四行不匹配的原因是(并且在第二个上也永远不会匹配)的一个缺点是,正则表达式坚持
searchresult(
前面是.
或行首(^
),而在第二行和第四行,这是不正确的(它前面有一个空格)。变成了
这允许
searchresult(
在.
或new
之后。regex101上的演示