When the array argi has more than one partition, its only begins to find word from the second url of the array, but why? Correct it please in code. Here the part of it: I make regular expresion for search by title in url:
private final Pattern TITLE = Pattern.compile("\\<title\\>(.*)\\<\\/title\\>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
And searh logic here:
public String search(String url, String someword) {
try {
InputStreamReader in = new InputStreamReader(new URL(url).openStream(),"UTF-8");
StringBuilder input = new StringBuilder();
int ch;
while ((ch = in.read()) != -1) {
input.append((char) ch);
}
if (Pattern.compile(someword, Pattern.CASE_INSENSITIVE).matcher(input).find()) {
Matcher title = TITLE.matcher(input);
if (title.find()) {
return title.group(1);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (PatternSyntaxException e) {
e.printStackTrace();
}
return null;
}
String[] argi = {"http://localhost:8080/site/dipnagradi","http://localhost:8080/site/contacts"};
for (int i = 0; i < argi.length; i++) {
String result = search(argi[i], word);
if (result != null) {
str = "Search phrase " + "<b>"+ word + "</b>" + " have found " + "<a href=\"" + argi[i] + "\">" + result + "</a>"+ "<p></p>";
}
else{
str="Search word not found!";
}
if (word == null||word=="") {
str = "Enter a search word!";
}
}
return null;
}