Find one or more matching strings in the input
// Find one or more matching strings in the input.
Here we use the find method of the Mather class to find matching content.
Package match;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. URL;
Import java. util. regex. Matcher;
Import java. util. regex. Pattern;
Import java. util. regex. PatternSyntaxException;
Public class HrefMatch {
Public static void main (String [] args) throws IOException {
// TODO Auto-generated method stub
Try {
String urlString;
If (args. length> 0 ){
UrlString = args [0];
} Else {
UrlString = "http://java.sun.com ";
}
InputStreamReader in = new InputStreamReader (new URL (urlString). openStream ());
StringBuilder input = new StringBuilder ();
Int ch;
While (ch = in. read ())! =-1 ){
Input. append (char) ch );
}
String patternString = "] \ s *> ";
// Ignore string case sensitivity
Pattern pattern = Pattern. compile (patternString, Pattern. CASE_INSENSITIVE );
Matcher matcher = pattern. matcher (input );
While (matcher. find ()){
Int start = matcher. start ();
Int end = matcher. end ();
String match = input. substring (start, end );
System. out. println (match );
}
} Catch (PatternSyntaxException e ){
E. printStackTrace ();
}
}
}