Answer the question
In order to leave comments, you need to log in
Question about Matches in regex (Java)?
There is this code:
public class Test {
public static void main(String[] args) {
String htmlCode = getHtmlCode("http://www.некий_сайт.ru");
Pattern pattern = Pattern.compile("<a href=.*?>(.*?)</a>");
Matcher matcher = pattern.matcher(htmlCode);
if (matcher.matches()) {
System.out.println(1);
}
System.exit(0);
}
public static String getHtmlCode (String strURL) {
String str = "";
try {
URL url = new URL(strURL);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {str += line;}
reader.close();
} catch (MalformedURLException e) {e.printStackTrace();
} catch (UnknownHostException e) {e.printStackTrace();
} catch (IOException e) {e.printStackTrace();}
return str;
}
}
Answer the question
In order to leave comments, you need to log in
Ahhh, he asked everything himself answered:
instead of matcher.matches() you need matcher.find()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question