正則表達式獲取TABLE里的內容


//過濾\n 轉換成空
            String withoutNString=message.Replace("\n", "");
            //過濾\r 轉換成空
            String withoutRString = withoutNString.Replace("\r", "");
            //過濾\t 轉換成空
            String withoutTString = withoutRString.Replace("\t", "");
            //過濾\ 轉換成空
            String newString = withoutTString.Replace("\\", "");
            //獲取html中的body標簽
            String result = Regex.Match(newString, @"<body.*>.*</body>").ToString();
            //過濾注釋
            String result2 = Regex.Replace(result, @"<!--(?s).*?-->", "", RegexOptions.IgnoreCase);
            //過濾nbsp標簽
            String result3 = Regex.Replace(result2, @"&nbsp;", "", RegexOptions.IgnoreCase);
            //獲取body中的所有table
            Regex regex = new Regex(@"<table.*?>[\s\S]*?<\/table>");
            MatchCollection mc = regex.Matches(result3);
            //獲取集合類中自己需要的某個table
            String newHtmlStr = mc[3].ToString();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM