简体   繁体   English

用于Java中的html文本代码的正则表达式

[英]Regex for an html text code in Java

I have a html text file that has headings I would like to extract the only the text inside 我有一个html文本文件,标题我想提取内部的文本

Example: 例:

<h1 class="title"><a href="dtb.htm#rgn_txt_0001_0001">Fire Safety</a></h1>
<h1><a href="dtb.htm#rgn_txt_0002_0001">About this book</a></h1>
<h1><a href="dtb.htm#rgn_par_0002_0008">1</a></h1>
<h1><a href="dtb.htm#rgn_txt_0003_0001">Contents of this book</a></h1>

I would like extract only the following text from HTML code: 我想从HTML代码中仅提取以下文本:

Fire Safety, About this book, 1, Contents of this book 消防安全,关于本书,1,本书的内容

I tried lot of things like: 我尝试过很多东西:

Pattern pattern = Pattern.compile("<a[^>]href\\s=\\s*\"\\s*([^\"]*)");
Matcher matcher = pattern.matcher(input);

where input is the html data. 其中input是html数据。

Didn't get any results on the console or sometimes are i am getting only href :( 没有在控制台上得到任何结果或有时是我只得到href :(

How do I get to fix this? 我该如何解决这个问题?

Let me know! 让我知道! Thanks! 谢谢!

我强烈建议使用HTML解析器,如TagSoupJerichoNekoHTMLHTML Parser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM