Regex to detect IE9 and below?

白昼怎懂夜的黑 提交于 2019-12-24 04:23:29

问题


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/

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)

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?


回答1:


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

MSIE [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]




回答2:


only match 5-9 and not 1-9. There are virtually 0 people using IE 4 and below.



来源:https://stackoverflow.com/questions/27239932/regex-to-detect-ie9-and-below

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!