我很好奇 /i
是什么:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}};
}
来源:https://www.sitepoint.com/navigator-useragent-mobiles-including-ipad/
谁能告诉我 /i
到底是什么?我在很多网站上搜索了有关 navigator.userAgent.Match 的信息,但没有一个解释 /i
是什么,有时它也是 /g
最佳答案
/heregoesregex/flags
是许多语言(包括 javascript)中正则表达式的文字。在最后一个斜杠之后,您可以指定正则表达式的标志。 JavaScript 的可用标志列表包括:
- g 全局搜索。
- i 不区分大小写的搜索。
- m多行搜索。
- y 从当前位置开始匹配的“粘性”搜索 目标字符串中的位置
关于javascript - navigator.userAgent.match 中的/i 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40527534/