Java Regex从HTML锚点( … )标记中获取文本
我正在尝试在某个标签内获取文本。 如果我有:
Found
我希望能够检索Found
文本。
我正在尝试使用正则表达式。 如果保持不变但我没有,我能够做到这一点。
到目前为止我有这个:
Pattern titleFinder = Pattern.compile( ".*[a-zA-Z0-9 ]* ([a-zA-Z0-9 ]*).*" );
我认为最后两部分 – ([a-zA-Z0-9 ]*).*
– 还可以,但我不知道该如何处理第一部分。
正如他们所说,不要使用正则表达式来解析HTML。 如果你意识到这些缺点,你可能会侥幸逃脱。 尝试
Pattern titleFinder = Pattern.compile("]*>(.*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Matcher regexMatcher = titleFinder.matcher(subjectString); while (regexMatcher.find()) { // matched text: regexMatcher.group(1) }
将迭代字符串中的所有匹配项。
str.replaceAll("?a>", "");
这是在线ideone演示
以下是类似主题: 如何仅从文本中删除标记?