Import java.util.ArrayList;
Import Java.util.Iterator;
Import java.util.List;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
public class Test {
public static void Main (String args[]) {
String html = "<title>abcd</title>gsdggas<title></title>jkll<title>005</title > ";
Simple example, equivalent to String html=gethtml (string urlstring);
List resultlist = getcontext (HTML);
for (Iterator iterator = Resultlist.iterator (); Iterator.hasnext ();) {
String context = (string) iterator.next ();
SYSTEM.OUT.PRINTLN (context);
}
}
/**
* Extract the text XXXX in "<title>XXXX</title>"
* @param HTML document content to parse
* @return Resolution results, can be multiple matches, each matching results in the document appear in order to add in the results list
*/
public static List GetContext (String html) {
List resultlist = new ArrayList ();
Pattern p = pattern.compile ("<title> ([^</title>]*)");//matching document at end of <title> beginning,</title>
Matcher m = p.matcher (HTML);//Start compiling
while (M.find ()) {
Resultlist.add (M.group (1));//Get the matched part
}
return resultlist;
}
}