【发布时间】:2010-08-10 19:36:31
【问题描述】:
可能重复:
Extract text and links from HTML using Regular Expressions
给定一个包含 HTML 的字符串,例如:
<td scope="row">1</td> <td scope="row"></td> <td scope="row"><a href="/Archives/directory.htm">directoryfile.htm</a></td> <td scope="row">directoryfile</td> <td scope="row">104569</td> </tr> <tr class="blueRow"> <td scope="row">2</td> <td scope="row"></td> <td scope="row"><a href="/Archives/historicaldata.htm</a></td> <td scope="row">historicaldata</td> <td scope="row">40361</td> </tr> <tr> <td scope="row"> </td> <td scope="row"><span class="blue">Complete submission text file</span></td> <td scope="row"><a href="/Archives/businessagenda.txt</a></td> <td scope="row">businessagenda;</td> <td scope="row">146701</td>
我只想使用正则表达式获取历史数据的链接。但是,我的程序似乎没有找到链接,并且我没有看到问题,因为正则表达式适用于测试仪。大家看看有什么问题吗?
我知道正则表达式不是与 HTML 一起使用的最佳选择,但我只是想尝试一下。谢谢大家!
模式数据 = Pattern.compile("Archives.*\s.*historicaldata");
匹配器 test1= data.matcher(inputHTML);
而 (test1.find()) {
System.out.println("测试:现在匹配"); // 不打印
}
【问题讨论】:
-
鸭子,在“ARRGGH!用正则表达式解析 Html!”之前人群向你扔鞋。
-
我会看到您的“使用正则表达式解析 html”,并提出“布局表”、“以颜色命名的 css 类”和“文件名中的 .htm 而不是 .html”
标签: regex