正则表达式检测IE9及以下? [英] Regex to detect IE9 and below?

查看:33
本文介绍了正则表达式检测IE9及以下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Java 编写一个正则表达式模式来检测用户代理是否小于或等于 Internet Explorer 9.这里有很多示例:

I am trying to write a regex pattern in Java to detect if a user agent is less than or equal to Internet Explorer 9. There are quite a few examples here:

http://www.useragentstring.com/pages/Internet%20Explorer/

主要要点是用户代理字符串中有一个字符串,名为:MSIE XXXX.我当前的正则表达式模式是这样的:

The main gist is there will be a string in the user agent string called: "MSIE XXXX). My current regex pattern is this:

MSIE ([1-9]|9)

除了在我执行 MSIE 10.0 或 MSIE 11.0 匹配时出现问题之外,这似乎有效.关于如何只匹配 1-9 而没有 10.0 或 11 的任何想法?

Which seems to work except there are problems when I do MSIE 10.0 or MSIE 11.0 it matches. Any ideas on how to only match 1-9 and no 10.0 or 11?

推荐答案

在旧版本中,主版本号后面总是有一个点,你可以在你的正则表达式中使用它:

In old versions, there is always a dot after the major version number, you can use it in your regex :

MSIE [1-9]\.

另一种写法是期望一个 1 到 9 之间的数字后跟一个非数字字符:

Another way to write it is to expect one number between 1 and 9 followed by a non number char :

MSIE [1-9][^0-9]

这篇关于正则表达式检测IE9及以下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆