for (String line; (line = reader.readLine()) != null;) {//reads html page
Pattern p = Pattern.compile("https://secure\\.runescape\\.com/m=displaynames/s=[a-zA-Z1-9*]+/check_name\\.ws\\?displayname=");
Matcher m = p.matcher(line);
if (m.find()) {
System.out.println(m.group(0));
}
}
The string in the page looks like: callback_request("https://secure.runescape.com/m=displaynames/s=p2FAuYaMFDgzntbDei*324JUo*3ozJ7hR*h1KNlxc6kPaBeKCBrdKH5kzljYSfUa/check_name.ws?displayname=" + escape(text), handleResult);
However it’s not returning any results. Am I doing something wrong? Apologies for the noobish question, I’m still learning java.
As per your regular expression you are missing a
?in the test expression.I suppose in the
displayname=?the ending?is coming from theescape(text)therefore if you make the?in thedisplayname=?as optional then it would work. Check the above code for more detail.>>Output:
https://secure.runescape.com/m=displaynames/s=p2FAuYaMFDgzntbDei*324JUo*3ozJ7hR*h1KNlxc6kPaBeKCBrdKH5kzljYSfUa/check_name.ws?displayname=