Find one or more matching strings in the input.
Here is the Find method for the Mather class to find the 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 = "<a\\s+href\\s*=\\s* (\" [^\ "]*\" |[ ^\\s>]\\s*> ";
Ignore string case
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 ();
}
}
}
Find one or more matching strings in the input