正則表達式 提取 html 標籤的內容


例如:
<h1>內容<h1>

正則表達式:

/<.+?>(.+?)<.+?>/


Java實現:

        

        String htmlStr = "<h1>XXX<h1/><h2>YYY<h2/>";

        Pattern pattern = Pattern.compile("<.+?>(.+?)<.+?>");
        Matcher matcher = pattern.matcher(htmlStr);
        // 獲得結果集
        while (matcher.find()) {
            System.out.println(matcher.group(1));
        }


發佈了25 篇原創文章 · 獲贊 6 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章