【发布时间】:2014-12-31 16:40:56
【问题描述】:
考虑以下 C# 代码:
string s = System.IO.File.ReadAllText("C:\\_Temporary\\MyFile.txt");
var reg = new System.Text.RegularExpressions.Regex("\"Second\" -- (.+)");
var val = reg.Match(s).Groups[1].Value;
或者这个在 VB.NET 中:
Dim s = System.IO.File.ReadAllText("C:\_Temporary\MyFile.txt")
Dim reg = New System.Text.RegularExpressions.Regex("""Second"" -- (.+)")
Dim val = reg.Match(s).Groups(1).Value
还有C:\_Temporary\MyFile.txt的内容:
“First”——这是我的第一个项目。
“第二个”——这是我的第二个项目。
“第三”——这是我的第三项。
如果 RegEx 元字符 . 排除了所有行尾字符(并且确实阻止了匹配返回 "Second" -- here is my second item. 下面的其余内容),为什么 val 以回车(\r)?
【问题讨论】:
-
\r从什么时候开始表示换行符?哦,对了,Windows 逻辑。