Regex to detect IE 5, 6, 7, and 8 but no others

I have compiled this regex that should only return a match, where the user agent string is IE 5, 6, 7, and 8. Obviously, one of the main goals here is to avoid the confusing IE11 user agent string ..

Is this Regex valid (I missed something)?

.*MSIE [5-8]\b((?!Trident/4.0)).*

UPDATE

Below are all user agent strings for 5, 6, 7, and 8. And none of 9, 10. However, it matches one for IE11 returned from .Net using Request.UserAgent

'Mozilla / 4.0 (compatible; MSIE 7.0; Windows NT 6.3; WOW64; Trident / 7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729 ) '

^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/6\.0\)).*$
+4
source share
1 answer

The following is a list of user agent strings in versions of IE . To verify the authenticity of the IE 5, 6, 7, and 8 user agent string, you only need to check "Trident / 6.0" at the end.

Use this regex: ^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/[5-9]\.0).*$

See the regex101 example .

EDIT

According to the MSDN user agent documentation ,

When the F12 developer tools are used to change the browser mode of Internet Explorer, the version token of the user-agent string is changed so that the browser looks earlier.

, Internet Explorer , , , - , .

, Trident user-agent.

, , .

Token         Description
Trident/7.0   IE11
Trident/6.0   Internet Explorer 10
Trident/5.0   Internet Explorer 9
Trident/4.0   Internet Explorer 8

, , MSIE "Trident/5.0", "Trident/7.0": ^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/[5-9]\.0).*$. , "Trident/10" +. , : ^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/(?:[5-9]|1[0-9])\.0).*$.

+6

All Articles