Find one or more matching strings in the input

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.