我正在尝试使用 C# 中的 RegEx 从电子邮件中解析边界标记。
数据采用以下格式之一:
boundary=\"--==_mimepart_5c1ceb26ac136_211222489141168988\";
boundary=\"----------=_1545338372-18873-1534\"
使用:
string pattern = "(-+.+)";
Regex regex = new Regex(pattern);
string boundary = (from x in email where x.Contains("boundary=\"") select x).FirstOrDefault();
MatchCollection matches = regex.Matches(boundary);
我得到的结果是:
--==_mimepart_5c1ceb26ac136_211222489141168988\";
如果我将模式更改为:
string pattern = "(-+.+)(?=\\\\)";
我得到零匹配。我也试过 "(-+.+)(\\)"并且仍然得到零匹配。使用 Regexer 和 Regex Storm,该模式准确地捕获了我需要的内容。谁能帮我弄清楚为什么会失败?
最佳答案
关于c# Regex 前瞻失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53891915/