西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)C#.NET → C# html抽取所有文本內(nèi)容的正則表達式

C# html抽取所有文本內(nèi)容的正則表達式

相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時間:2010/11/25 15:16:08字體大小:A-A+

作者:佚名點擊:620次評論:0次標簽: 文本內(nèi)容 正則表達

  • 類型:電子資料大。3.9M語言:中文 評分:10.0
  • 標簽:
立即下載
只抽取HTML中 所有<P></p>之間的文本的正則表達式:(?is)<p[^>]*>(?><p[^>]*>(?<o>)|</p>(?<-o>)|(?:(?!</?p\b).)*)*(?(o)(?!))</p>

測試代碼:
public static void Main(string[] args)
{
           
string text="<p>sdfasdfsa</p>sxcvxc<Img src=><p>23424</p>";
           
string regex=@"(?is)<p[^>]*>(?><p[^>]*>(?<o>)|</p>(?<-o>)|(?:(?!</?p\b).)*)*(?(o)(?!))</p>";
            GetListByHtml(text, regex);
            Console.ReadKey();
        }

public static void GetListByHtml(string text,string pat)
        {
            System.Text.RegularExpressions.Regex r
= new System.Text.RegularExpressions.Regex(pat, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Match m
= r.Match(text);
           
//int matchCount = 0;
            while (m.Success)
            {
                Console.WriteLine(m.Value);
                m
= m.NextMatch();
            }
        }

這是抽取herf的例子 string regexs = "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']";

    相關(guān)評論

    閱讀本文后您有什么感想? 已有人給出評價!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評論

    最新評論

    發(fā)表評論 查看所有評論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)