1

Parsing the user-agent header I need to find out if I am dealing with IE-8 or earlier:

<= IE8

So the regex should return true in the following cases:

(compatible; MSIE 8.0;...)
(compatible; MSIE 7.0;...)
etc. 

The following should yield false:

(compatible; MSIE 9.0;...)

This following regex does not work:

"MSIE [6-8]\."
1
  • This works for me: "(?i).*MSIE [5-8]\..*" Commented Feb 16, 2012 at 11:07

2 Answers 2

4

Your pattern should work if you escape the backslash, or did you mean JavaScript?. (in which case it should work)

"(?i)MSIE\\s+[5-8]\\.\\d+"

Explanation:

  • (?i) makes the match case insensitive
  • MSIE matches the string MSIE
  • \\s+ one or more spaces
  • [5-8] matches digits 5 to 8
  • \\. match a dot
  • \\d+ one or more digits
Sign up to request clarification or add additional context in comments.

1 Comment

It still does not work if I use java.regex (with Scala): val ieMatcher = """(?i)MSIE\\s+[5-8]\\.\\d+""".r.pattern def isIE(str: String) = ieMatcher.matcher(str).matches()
0

You can use character groups to match versions, f.i. [678]\.0.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.