我不知道该怎么做。
基本上使用java我正在尝试:
- 从网站读取 html
我想查找某个字符串后面的内容,在本例中是
title="
- 将其存储在字符串中。
第一步和最后一步对我来说很简单,但我没有运气(并且从未使用正则表达式)。
我相信这是我需要的开始:
String regex = "(?<=title=\")\\S+";
Pattern name = Pattern.compile(regex);
之后我就不知道了。有什么帮助吗?
最佳答案
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String EXAMPLE_TEST = "......";
Pattern pattern = Pattern.compile("(?<=title=\")(\\S+)")
Matcher matcher = pattern.matcher(EXAMPLE_TEST);
while (matcher.find()) {
System.out.println(matcher.group());
}
注意:您可能会考虑使用正则表达式模式 (?<=title=\")([^\"]*)
关于java - 将字符串与 html 输入中的正则表达式进行匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11692577/