日期:2014-05-17 浏览次数:20805 次
package test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegExDemo { public static void main(String[] args) { String regex = "<INPUT TYPE=\"(\\w+)\" NAME=\"(\\w+)\" SIZE=\"(\\d+)\" value=\"([a-zA-Z\\d-]+)\"[/]{0,1}>"; String text = "<html>\n" + " <head>\n" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" + "\n" + " </head>\n" + "<BODY >\n" + "<FORM METHOD=POST ACTION=\"http://www.gd.aaa.local/pkmslogin.form\" name=\"loginform\">\n" + "<INPUT TYPE=\"HIDDEN\" NAME=\"username\" SIZE=\"15\" value=\"000048718\">\n" + "<INPUT TYPE=\"HIDDEN\" NAME=\"password\" SIZE=\"15\" value=\"abcd\"/>\n" + "<INPUT TYPE=\"HIDDEN\" NAME=\"login-form-type\" VALUE=\"pwd\">\n" + "</FORM>\n" + "\n" + "<script>\n" + " document.loginform.submit(); \n" + "</script>\n" + "\n" + "</BODY>\n" + "</html>"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group(4)); } } }