Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

常见手机品牌正则匹配

阅读数:次 2016-07-28
字数统计: 3.3k字   |   阅读时长≈ 18分

思路:先分析各种手机品牌的请求头中user_agent的特点,总结出规律。然后用正则匹配来进行分类,并进行统计。最后在页面中实现可视化显示。

一.各种终端UA格式(以安卓系统为例)

Tablet

1
Mozilla/5.0 (Linux; Android android-version; product-model Build/product-build) AppleWebKit/webkit-version (KHTML, like Gecko) Silk/browser-version like Chrome/chrome-version Safari/webkit-version

Desktop

1
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/webkit-version (KHTML, like Gecko) Silk/browser-version like Chrome/chrome-version Safari/webkit-version

Mobile

1
Mozilla/5.0 (Linux; Android android-version; product-model Build/product-build) AppleWebKit/webkit-version (KHTML, like Gecko) Silk/browser-version like Chrome/chrome-version Mobile Safari/webkit-version

Note

1
2
3
4
5
6
7
8
9
10
Red and italics indicates variable fields, which are described below.
Template fields
android-version – The Android platform version (for example, 4.4.3).
product-model – The value of Build.MODEL (for example, KFTT).
For a complete list of the product models, see Screen Resolution.
product-build – The value of Build.ID (for example, IML74K).
webkit-version – Indicates the version of WebKit used (for example, 535.19). The version can change whenever the Fire device receives a software update.
browser-version – Indicates the version of the Amazon Silk browser (for example, 44.1.54). The version can change whenever the Fire device receives a software update.
chrome-version – The version of Google Chrome with which the Amazon Silk browser is compatible.
User Agent String Examples

二. 品牌-brand

search key_word: user-agent detect type of platform device;
                 List of user agents for mobile phones
                 

按照使用量降序

  1. 手机phone
    1.1 国外品牌
    iphone
    blackberry
    nokia lumia
    samsung
    Sony
    Nokia
    Kindle Fire HD(KFTT)

1.2 国内品牌
华为,huawei和honor两个品牌,PLK-AL10是荣耀7
小米,MI
2. 平板tablet
3. 笔记本desktop

三. 思考问题

  1. db中user_agent为空的,怎么得出来machine_brand?
  2. 手机类型应该是从数据库中取出,而非实时分析统计的。
  3. 只要手机品牌信息,不要型号等后缀。
  4. user_agent 是否完整?
  5. 优化还是改型
  6. 数据怎么打到前台。

数据库操作:resources-com.xxx-portal.dao-*.xml

1
2
3
4
5
6
7
8
9
10
String userAgent = request.getHeader("User-Agent");
if(userAgent.indexOf("Mozilla")!=-1 && userAgent.indexOf("iPhone")!=-1 || userAgent.indexOf("Android")!=-1 ){
response.sendRedirect("页面1");
}else if(userAgent.indexOf("Opera")!=-1 && userAgent.indexOf("Opera Mini")!=-1 || userAgent.indexOf("BlackBerry")!=-1){
response.sendRedirect("页面2");
}else if(userAgent.indexOf("Mozilla")!=-1 && userAgent.indexOf("Windows")!=-1){
response.sendRedirect("页面3");
}else{
response.sendRedirect("页面1");
}
1
2
3
4
5
6
7
8
9
10
//以build匹配方式,虽然可以得到build前面的型号,但不知道手机品牌,需要分类。
/;\s?([^;]+?)\s?(Build)?/i //..末尾的/i表示不区分大小写

Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/");
Matcher matcher = pattern.matcher(userAgent);
String model = null;
if (matcher.find()) {
model = matcher.group(1).trim();//group从1
log.debug("通过userAgent解析出机型:" + model);
}

Build下一级再分一下,还是直接匹配。

不是所有的UA都有build。

1
2
3
4
Pattern p = Pattern.compile("a*b");   //将给定的正则表达式编译到模式中。
Matcher m = p.matcher("aaaaab");//创建匹配给定输入与此模式的匹配器。
boolean b = m.matches();
String c = m.group(1).trim();

pattern取出(…xxx)的字符串?

用字符串匹配方法String.comtains(),
正则怎么表示出来。数组?
序列化所有的正则,对应到机型。?
循环正则(用数组对象来表达),匹配到即跳出

java正则特殊之处:

  1. 转义字符时需要两个//
  2. 不区分大小写在前面加上(?i),而js是后面加/i

四. 验证

写一个单页面?访问数据库

  1. 先用单个数据做实验,先看能不能匹配到,再去想怎么做模型
  2. 建立分类模型
    初级的正则已经完成编辑,需要 在分类,用更合理的方法,运算太复杂,循环次数影响性能。
  3. 拷贝到本地数据库,jdbc?查到数据
    jdbc取数据(20160725),取出之后经过分析,再在数据库建一个字段,储存分析结果
  4. 分析结果展示,统计类型数
1
SELECT * FROM portal_logrecord WHERE MACHINE_BRAND LIKE "%asus%";//模糊查询

不要忽略手机的更新速度,注意最新机型。
尽量用小写,减少运算。

五. 最终匹配代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
//java版本,js版本见-七[资源参考]
Pattern patAcer = Pattern.compile("(?i)((acer|a(?:101|110|200|210|211|500|501|510|511|700|701)[);/\\s]|Android.*V3[67]0[);/\\s]|Android.*Z1[23456]0\\sBuild|Android.*Z500\\sBuild|A1-830|A1-81[01]|A3-A[12][01]|B1-7[1235][01]|B1-810|B1-A71|E39\\sBuild|S5[12]0\\sBuild|DA[0-9]+HQ?L[);/\\s]))"); //Acer
Pattern patAlcatel = Pattern.compile("(?i)(Alcatel|Alc[a-z0-9]+|One[ _]?Touch)"); //Alcatel
Pattern patAloes = Pattern.compile("(?i)(\\saloes\\sbuild)"); //Aloes奥洛斯
Pattern patAmazon = Pattern.compile("(?i)(kindle|kf[A-z]+|KF(?:OT|TT|JWI|JWA|SOWI|A[PRS]WI|THWI|SAW[IA])[);/ ]|Silk/\\d+\\.\\d+|Amazon (?:Tate|Jem)|AFT[BM]|SD4930UR)"); //kindle |(sd|kf[0349hijorstuw]+)影响了droid-Verizon
Pattern patAmoi = Pattern.compile("(?i)(\\samoi\\s|A862W)"); //Amoi夏新手机
Pattern patAole = Pattern.compile("(?i)(\\saole(dior)?\\sbuild)"); //Aole奥乐手机
Pattern patApple = Pattern.compile("(?i)((?:iTunes-)?AppleTV|(?:Apple-)?(?:iPad|iPhone)|iPh[0-9],[0-9]|CFNetwork|(?:Apple-)?iPod|ipod\\s{0,1}tv)"); //Apple
Pattern patAsus = Pattern.compile("(?i)(asus|Transformer|TF300T|Slider SL101|PadFone|ME302(?:C|KL)|ME301T|ME371MG|ME17(?:1|2V|3X)|(?:K0[01][0-9a-z]|Z00D)[);/ ])"); //Asus
Pattern patArchos = Pattern.compile("(?i)(Archos)"); //法国爱可视手机
Pattern patBenq = Pattern.compile("(?i)((benq)[\\s_-]?([\\w-]+)*)"); //Benq
Pattern patBestsonny = Pattern.compile("(?i)(Bestsonny)"); //Bestsonny
Pattern patBeierfeng = Pattern.compile("(?i)(\\sbf_t\\d{2}\\sbuild)"); //BF贝尔丰
Pattern patBird = Pattern.compile("(?i)(\\sbird\\s|bird[\\-. _]([^;/]+))"); //Bird波导
Pattern patBlackBerry = Pattern.compile("(?i)(playbook|blackberry|bb10;\\s(\\w+)|\\sq5\\sbuild)"); //BlackBerry
Pattern patChanghong = Pattern.compile("(?i)(changhong)"); //Changhong 长虹
Pattern patCarNavi = Pattern.compile("(?i)(carnavi)"); //Car Navigation汽车导航
Pattern patCoolpad = Pattern.compile("(?i)((?:YL-)?coolpad|8190q[ ;/\\)]|8295 build)"); //Coolpad 酷派
Pattern patDell = Pattern.compile("(?i)(dell|dell\\s(strea[kpr\\s\\d]*[\\dko])|(001dl)|venue|xcd35)"); //Dell
Pattern patGionee = Pattern.compile("(?i)(gionee|(?:GIO-)?GIONEE[ _-]?[a-z0-9]+|(?:Dream_D1|V188S?|GN[0-9]{3,4}[a-z]?)[);/ ])");//GiONEE金立
Pattern patGoogle = Pattern.compile("(?i)(Google|nexus|GoogleTV|Glass|CrKey[^a-z0-9]|Talk)"); //Google
Pattern patHaier = Pattern.compile("(?i)(haier|;\\sqk-6385t\\sbuild|(?:HW-)?W(?:716|757|860|970)[);/ ])"); //Haier
Pattern patHisense = Pattern.compile("(?i)((?:HS-)?Hisense ([^;/]+) Build|Hisense [^);/]+|HS-(?:U|EG?|I|T|X)[0-9]+[a-z0-9\\-]*|E270BSA|M470BS[AE]|E2281)"); //Hisense
Pattern patHP = Pattern.compile("(?i)(hp|touchpad|android\\s.+slate|hp-tablet|HP ?iPAQ|webOS.*P160U|HP Slate|HP [78]|Compaq [7|8])"); //HP
Pattern patHTC = Pattern.compile("(?i)((htc)|Sprint T7380|EVO|(sprint\\s(\\w+))|ADR(?!910L)[a-z0-9]+|Amaze[ _]4G[);/ ]|(Desire|Sensation|Evo ?3D|IncredibleS|Wildfire|Butterfly)[ _]?([^;/]+) Build|(Amaze[ _]4G|One ?[XELSV\\+]+)[);/ ]|SPV E6[05]0|One M8|X525a|PG86100|PC36100|XV6975|PJ83100[);/ ])"); //HTC
Pattern patHuawei = Pattern.compile("(?i)(huawei|honor|Linux;\\sU;\\sandroid[\\s\\.\\d\\w;-]{15}media\\spad\\sbuild\\/jdq39|\\sch[em][12]?-[ctu]l\\d{2}[hm]?\\sbuild)|(HW-)?(?:Huawei|Ideos|Honor[ _]|(?:H60-L(?:01|02|03|04|11|12)|H30-(?:C00|L01M?|L02|U10|T00|T10)|G621-TL00M?|PLK-(?:AL10|CL00|TL00|TL01H?|UL00|L01)|SCL-(?:AL00|CL00|TL00H?)|CH(?:E2?|M)-[CUT]L00[HM]?|CHE1-CL[12]0|CHE2-L11|U(?:8230|8500|8661|8665|8667|8800|8818|8860|9200|9508))[);/ ])"); //Huawei
Pattern patInnos = Pattern.compile("(?i)(\\sd10cf\\sbuild)"); //Innos奕骆
Pattern patJolla = Pattern.compile("(?i)(linux;.+((jolla));)"); //Jolla,芬兰手机品牌
Pattern patLenovo = Pattern.compile("(?i)((?:LNV-)?lenovo|IdeaTab|IdeaPad|Thinkpad|Yoga Tablet)"); //Lenovo
Pattern patLephone = Pattern.compile("(?i)(\\slephone\\st\\d)"); //Lephone 乐丰
Pattern patLeshi = Pattern.compile("(?i)(;\\sle(tv)?\\sx\\d{3}\\sbuild)"); //leshi
Pattern patLG = Pattern.compile("(?i)(lg|lg[e;\\s\\/-]+(\\w+)*|portalmmm/2\\.0 (?:KE|KG|KP|L3)|(?:VX[0-9]+|L-0[12]D|L-07C|P713)[);/ ]|NetCast)"); //LG
Pattern patLingwin = Pattern.compile("(?i)(Lingwin)"); //Lingwin灵韵手机
Pattern patMeizu = Pattern.compile("(?i)(meizu|;\\sm\\d\\smetal\\sbuild|;\\smx\\d.+build|;\\sm\\d\\snote\\sbuild|;\\smz-m\\dmetal\\sbuild|;\\spro\\s[56]\\sbuild)|(M04[05]|M35[1356]|MX[ -]?[234](?: Pro)?|(?:MZ-)?m[12] note|(?:MZ-)?M57[18]C)[);/ ]"); //Meizu
Pattern patMicrosoft = Pattern.compile("(?i)(xbox|KIN\\.(One|Two))"); //Microsoft ,是否加windows|?
Pattern patMotorola = Pattern.compile("(?i)(MB860|DCT-700|Xoom|\\s(milestone|droid(?:[2-4x]|\\s(?:bionic|x2|pro|razr))?(:?\\s4g)?)[\\w\\s]+build\\/|mot[\\s-]?(\\w+)*|(XT\\d{3,4}) build\\/|android.+\\s(mz60\\d|xoom[\\s2]{0,2})\\sbuild\\/|MOT|(?<!AN)DROID ?(?:Build|[a-z0-9]+)|portalmmm/2.0 (?:E378i|L6|L7|v3)|XOOM [^;/]*Build|(?:XT|MZ|MB|ME)[0-9]{3,4}[a-z]?(?:\\(Defy\\))?(?: Build|\\)))"); //Motorola
Pattern patNintendo = Pattern.compile("(?i)((nintendo)\\s([wids3u]+))"); //任天堂
Pattern patNokia = Pattern.compile("(?i)(Nokia|Lumia|Maemo RX|portalmmm/2\\.0 N7|portalmmm/2\\.0 NK|nok[0-9]+|Symbian.*\\s([a-z0-9]+)$|RX-51 N900|(maemo|nokia).*(n900|lumia\\s\\d+)|(nokia)[\\s_-]?([\\w-]+)*)"); //Nokia
Pattern patNook = Pattern.compile("(?i)(\\s(nook)[\\w\\s]+build\\/(\\w+))"); //nook
Pattern patNvidia = Pattern.compile("(?i)(shield|TegraNote-P1640)"); //Nvidia
Pattern patOppo = Pattern.compile("(?i)(oppo|android.+find\\s\\d\\sbuild|Android.+zh-cn;\\sr.+build|r1001|x9006|r2001|u707|x909|a31\\sr\\d{3}t?\\sbuild|(?:OB-)?OPPO[ _]?([a-z0-9]+)|N1T|(?:X90[07][067]|U707T?|X909T?|R(?:10[01]1|2001|201[07]|6007|7005|7007|80[13579]|81[13579]|82[01379]|83[013]|800[067]|8015|810[679]|811[13]|820[057])[KLSTW]?)|N520[79]|N5117[);/ ])"); //Oppo
Pattern patOwwo = Pattern.compile("(?i)(;\\sq03\\sbuild)"); //Owwo欧沃
Pattern patPalm = Pattern.compile("(?i)((palm(?=\\-))[\\s_-]?([\\w-]+)*)"); //Palm
Pattern patPhilips = Pattern.compile("(?i)(Philips|AND1E[);/ ]|NETTV/)"); //Philips
Pattern patPlaystation = Pattern.compile("(?i)(playstation)"); //Playstation
Pattern patSamsung = Pattern.compile("(?i)(samsung|(s[cgp]h-\\w+|gt-\\w+|sm-n900)|(sam[sung]*)[\\s-]*(\\w+-?[\\w-]*)*|(SM-[AGPT]\\w+)|sec-((sgh\\w+))|(samsung);smarttv|EK-G[CN][0-9]{3}|YP-(G[SIPB]?1|G[57]0|GB70D|Maple |SC-(?:02C|04E|01F)|N[57]100|N5110|N9100|S(?:CH|GH|PH|EC|AM|HV|HW|M)-|SMART-TV|GT-|Galaxy|(?:portalmmm|o2imode)/2\\.0 [SZ]|sam[rua]|vollo Vi86[);/ ]|(?:OTV-)?SMT-E5015|ISW11SC))"); //Samsung
Pattern patSharp = Pattern.compile("(?i)(\\(dtv[\\);].+(aquos)|SH-0|SBM\\d+SH)"); //Sharp
Pattern patSony = Pattern.compile("(?i)(Sony(?: ?Ericsson)?|SGP|Xperia|C1[569]0[45]|C2[01]0[45]|C2305|C530[236]|C550[23]|C6[56]0[236]|C6616|C68(?:0[26]|[34]3)|C69(?:0[236]|16|43)|D200[45]|D21(?:0[45]|14)|D22(?:0[236]|12|43)|D230[2356]|D240[36]|D25(?:02|33)|D510[236]|D530[36]|D5322|D5503|D58[03]3|D65(?:0[23]|43)|D66[05]3|E2303|E58[02]3|E6553|(?:WT|LT|SO|ST|SK|MK)[0-9]+[a-z]*[0-9]*(?: Build|\\))|X?L39H|XM50[ht]|W960|portalmmm/2\\.0 K|S3[69]h|X10[ia]v?|E1[05][ai]v?|MT[0-9]{2}[a-z]? Build|SO-0(?:[345]D|[234]E|[12]C|[1235]F|[12]G)|R800[aix]|LiveWithWalkman)"); //Sony
Pattern patTcl = Pattern.compile("(?i)(tcl|TCL[ -][a-z0-9]+|TCL[_ -][^;/]+ Build)"); //tcl
Pattern patTianyu = Pattern.compile("(?i)(tianyu)"); //tianyu
Pattern patToshiba = Pattern.compile("(?i)(Toshiba|TSBNetTV/|portalmmm/[12].0\\sTS|T-01C|T-0[12]D|IS04|IS11T|AT1S0|AT300SE|AT(100|200|270|300|330|374|400|470|500|503|570|703|830))"); //Toshiba 东芝
Pattern patVivo = Pattern.compile("(?i)((?:viv-|bbg-)?vivo)"); //vivo
Pattern patXiaomi = Pattern.compile("(?i)(xiaomi|android[\\s\\d\\.;]{7,10}hm\\s|(hm[\\s\\-]note?[\\s]*(?:\\d\\w)?)|android.+(mi[\\s\\-_]*(?:one|one[\\s_]plus)?[\\s_]*(?:\\d\\w)?)\\s+build|android.+mi\\s\\w+\\s|(MI [a-z0-9]+|MI-One[ _]?[a-z0-9]+)[);/ ]|HM ([^/;]+) Build|(2014501|2014011|201481[13]|201302[23]|2013061) Build|Redmi)"); //xiaomi
Pattern patZTE = Pattern.compile("(?i)(zte|AxonPhone|([a-z0-9]+)_USA_Cricket|(?:Blade S6|N9[15]8St|NX(?:403A|40[X2]|507J|503A|505J|506J|508J|510J|511J|513J|601J)|Z331|N9510|N9180|N9101|N9515|N952[01]|N9810|N799D|[UV]9180|[UV]9815|Z768G)[);/ ])"); //ZTE
//Acer
Matcher matAcer = patAcer.matcher(userAgentString);
if (matAcer.find()) {
productBrand = "Acer";
}
//Alcatel
Matcher matAlcatel = patAlcatel.matcher(userAgentString);
if (matAlcatel.find()) {
productBrand = "Alcatel";
}
//Aloes
Matcher matAloes = patAloes.matcher(userAgentString);
if (matAloes.find()) {
productBrand = "Aloes";
}
//Amazon
Matcher matAmazon = patAmazon.matcher(userAgentString);
if (matAmazon.find()) {
productBrand = "Amazon";
}
//Amoi夏新
Matcher matAmoi = patAmoi.matcher(userAgentString);
if (matAmoi.find()) {
productBrand = "Amoi";
}
//Aole奥乐
Matcher matAole = patAole.matcher(userAgentString);
if (matAole.find()) {
productBrand = "Aole";
}
//苹果
Matcher matApple = patApple.matcher(userAgentString);
if (matApple.find()) {
productBrand = "Apple";
}
//华硕
Matcher matAsus = patAsus.matcher(userAgentString);
if (matAsus.find()) {
productBrand = "Asus";
}
//法国爱可视手机
Matcher matArchos = patArchos.matcher(userAgentString);
if (matArchos.find()) {
productBrand = "Archos";
}
//Benq
Matcher matBenq= patBenq.matcher(userAgentString);
if (matBenq.find()) {
productBrand = "Benq";
}
//Bestsonny至尊宝手机-联发科MediaTek
Matcher matBestsonny = patBestsonny.matcher(userAgentString);
if (matBestsonny.find()) {
productBrand = "Bestsonny";
}
//Beierfeng贝尔丰手机
Matcher matBeierfeng = patBeierfeng.matcher(userAgentString);
if (matBeierfeng.find()) {
productBrand = "Beierfeng";
}
//bird波导手机
Matcher matBird = patBird.matcher(userAgentString);
if (matBird.find()) {
productBrand = "Bird";
}
//黑莓
Matcher matBlackBerry = patBlackBerry.matcher(userAgentString);
if (matBlackBerry.find()) {
productBrand = "BlackBerry";
}
//长虹
Matcher matChanghong = patChanghong.matcher(userAgentString);
if (matChanghong.find()) {
productBrand = "Changhong";
}
//CarNavigation汽车导航
Matcher matCarNavi= patCarNavi.matcher(userAgentString);
if (matCarNavi.find()) {
productBrand = "CarNavi";
}
//Coolpad 酷派
Matcher matCoolpad= patCoolpad.matcher(userAgentString);
if (matCoolpad.find()) {
productBrand = "Coolpad";
}
//Dell
Matcher matDell= patDell.matcher(userAgentString);
if (matDell.find()) {
productBrand = "Dell";
}
//Gionee
Matcher matGionee= patGionee.matcher(userAgentString);
if (matGionee.find()) {
productBrand = "Gionee";
}
//Google
Matcher matGoogle = patGoogle.matcher(userAgentString);
if (matGoogle.find()) {
productBrand = "Google";
}
//Haier
Matcher matHaier = patHaier.matcher(userAgentString);
if (matHaier.find()) {
productBrand = "Haier";
}
//Hisense
Matcher matHisense = patHisense.matcher(userAgentString);
if (matHisense.find()) {
productBrand = "Hisense";
}
//惠普
Matcher matHP = patHP.matcher(userAgentString);
if (matHP.find()) {
productBrand = "HP";
}
//HTC
Matcher matHTC = patHTC.matcher(userAgentString);
if (matHTC.find()) {
productBrand = "HTC";
}
//Huawei
Matcher matHuawei = patHuawei.matcher(userAgentString);
if (matHuawei.find()) {
productBrand = "Huawei";
}
//Innos奕骆
Matcher matInnos = patInnos.matcher(userAgentString);
if (matInnos.find()) {
productBrand = "Innos";
}
//Jolla
Matcher matJolla = patJolla.matcher(userAgentString);
if (matJolla.find()) {
productBrand = "Jolla";
}
//Lenovo
Matcher matLenovo = patLenovo.matcher(userAgentString);
if (matLenovo.find()) {
productBrand = "Lenovo";
}
//LG
Matcher matLG = patLG.matcher(userAgentString);
if (matLG.find()) {
productBrand = "LG";
}
//Lephone
Matcher matLephone = patLephone.matcher(userAgentString);
if (matLephone.find()) {
productBrand = "Lephone";
}
//Leshi
Matcher matLeshi = patLeshi.matcher(userAgentString);
if (matLeshi.find()) {
productBrand = "Leshi";
}
//Lingwin灵韵
Matcher matLingwin = patLingwin.matcher(userAgentString);
if (matLingwin.find()) {
productBrand = "Lingwin";
}
//Meizu
Matcher matMeizu = patMeizu.matcher(userAgentString);
if (matMeizu.find()) {
productBrand = "Meizu";
}
//Microsoft
Matcher matMicrosoft = patMicrosoft.matcher(userAgentString);
if (matMicrosoft.find()) {
productBrand = "Microsoft";
}
//Motorola
Matcher matMotorola = patMotorola.matcher(userAgentString);
if (matMotorola.find()) {
productBrand = "Motorola";
}
//Nintendo(任天堂)
Matcher matNintendo= patNintendo.matcher(userAgentString);
if (matNintendo.find()) {
productBrand = "Nintendo";
}
//Nokia
Matcher matNokia = patNokia.matcher(userAgentString);
if (matNokia.find()) {
productBrand = "Nokia";
}
//Nook
Matcher matNook= patNook.matcher(userAgentString);
if (matNook.find()) {
productBrand = "Nook";
}
//Nvidia
Matcher matNvidia = patNvidia.matcher(userAgentString);
if (matNvidia.find()) {
productBrand = "Nvidia";
}
//Oppo
Matcher matOppo = patOppo.matcher(userAgentString);
if (matOppo.find()) {
productBrand = "Oppo";
}
//Owwo
Matcher matOwwo = patOwwo.matcher(userAgentString);
if (matOwwo.find()) {
productBrand = "Owwo";
}
//Palm
Matcher matPalm= patPalm.matcher(userAgentString);
if (matPalm.find()) {
productBrand = "Palm";
}
//Philips
Matcher matPhilips= patPhilips.matcher(userAgentString);
if (matPhilips.find()) {
productBrand = "Philips";
}
//playstation
Matcher matPlaystation = patPlaystation.matcher(userAgentString);
if (matPlaystation.find()) {
productBrand = "Playstation";
}
//Samsung
Matcher matSamsung = patSamsung.matcher(userAgentString);
if (matSamsung.find()) {
productBrand = "Samsung";
}
//Sharp
Matcher matSharp = patSharp.matcher(userAgentString);
if (matSharp.find()) {
productBrand = "Sharp";
}
//Sony
Matcher matSony= patSony.matcher(userAgentString);
if (matSony.find()) {
productBrand = "Sony";
}
//TCL
Matcher matTcl= patTcl.matcher(userAgentString);
if (matTcl.find()) {
productBrand = "Tcl";
}
//Tianyu
Matcher matTianyu= patTianyu.matcher(userAgentString);
if (matTianyu.find()) {
productBrand = "Tianyu";
}
//Vivo
Matcher matVivo = patVivo.matcher(userAgentString);
if(matVivo.find()){
productBrand = "Vivo";
}
//Toshiba 东芝
Matcher matToshiba = patToshiba.matcher(userAgentString);
if(matToshiba.find()){
productBrand = "Toshiba";
}
//Xiaomi
Matcher matXiaomi = patXiaomi.matcher(userAgentString);
if (matXiaomi.find()) {
productBrand = "Xiaomi";
}
//ZTE
Matcher matZTE = patZTE.matcher(userAgentString);
if (matZTE.find()) {
productBrand = "ZTE";
}

六. 总结

  1. 以上正则能够匹配常见机型,得出品牌类型;不足之处是有几个重复识别了。
  2. 对正则有了更深入的了解,强大的工具
  3. java程序组成结构需要更深入的学习

七. Reference资源参考

常见User-Agent站点
UADetector:http://uadetector.sourceforge.net/
相关js库

  • 本文作者: Linking
  • 本文链接: https://linking.fun/2016/07/28/常见手机品牌正则匹配/
  • 版权声明: 版权所有,转载请注明出处!
  • 正则
  • 手机品牌匹配
  • cs

扫一扫,分享到微信

git学习一
Dwayne Wade's Emotional Letter to Miami Heat Fans
  1. 1. 一.各种终端UA格式(以安卓系统为例)
  2. 2. 二. 品牌-brand
  3. 3. 三. 思考问题
  4. 4. 四. 验证
  5. 5. 五. 最终匹配代码
  6. 6. 六. 总结
  7. 7. 七. Reference资源参考
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN