日期:2014-05-17 浏览次数:20444 次
StreamReader reader = new StreamReader("c:\\temp\\1.txt",Encoding.Default); string source = reader.ReadToEnd(); Regex reg = new Regex(@"(?is)((?<=UrlPath=')[^'>]+(?='))|((?<=\[CDATA\[)[^\[\]]+(?=\]))"); MatchCollection mc = reg.Matches(source); foreach (Match m in mc) { MessageBox.Show(m.Value); }
------解决方案--------------------
string pattern = @"(?i)(?<=<ScanInfo[^>]*?UrlPath=['""]([^'""]*?)['""][^>]*?>[\s\S]*?)<FileName[^>]*?>(?:(?!</FileName>).)*\[([^\[\]]*?\.[^\[\]]*?)\][^>]*?>\s*?</FileName>"; string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt foreach (Match m in Regex.Matches(tempStr, pattern)) { //循环输出 string UrlPath = m.Groups[1].Value;//2011\\05\\5667 string FileName = m.Groups[2].Value;//00表1.jpg }