Online search methods can not accurately show the model, the iphone can not be removed after the improvement, the code is as follows, but also need to further verify the changes:
Package org.mice.utils;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; /** * * Class Name: Miceutils.java * Class Description: Frequently Used class method * * @author CHENPH * @CreateDate: May 16, 2015 * @version 1.0/Public Class Miceutils {//Remove phone type from user-agent//static pattern = Pattern.compile ("; \\s? ( \\s*?\\s?\\s*?) \\s?
(build)?/"); Static pattern pattern = Pattern.compile ("; \\s?[ ^;\\s]*? (\\s?\\s*?) \\s?
(build)?/"); /** * Get phone type * @param agent * @return/public static string Getmobiletype (string agent) {if (Agent.indexof IP
Hone ")!=-1) {return" IPhone ";
} Matcher Matcher = Pattern.matcher (agent);
String model = NULL;
if (Matcher.find ()) {model = Matcher.group (1). Trim ();
return model;
Return ""; public static void Main (String args[]) {//string agent = "mozilla/5.0" (Linux; U Android 5.0.2; ZH-CN; XT1079 build/lxb22.99-7.1) applewebkit/534.30 (khtml, like Gecko) version/4.0 ucbrowser/10.4.0.5580.8.0 Mobile safari/534.30 "; String Agent = "mozilla/5.0" (IPhone; CPU iPhone os 8_2 like Mac os X;
ZH-CN) applewebkit/537.51.1 (khtml, like Gecko) mobile/12d508 ucbrowser/10.4.5.568 Mobile ";
System.out.println (Miceutils.getmobiletype (agent));
}
}